{"cells":[{"cell_type":"markdown","id":"6ae4651d","metadata":{"id":"6ae4651d"},"source":["The following additional libraries are needed to run this\n","notebook. Note that running on Colab is experimental, please report a Github\n","issue if you have any problem."]},{"cell_type":"code","execution_count":null,"id":"cb3334c1","metadata":{"id":"cb3334c1"},"outputs":[],"source":["!pip install git+https://github.com/d2l-ai/d2l-zh@release  # installing d2l\n"]},{"cell_type":"markdown","id":"86a38689","metadata":{"origin_pos":0,"id":"86a38689"},"source":["# 注意力提示\n",":label:`sec_attention-cues`\n","\n","感谢你对本书的关注，因为你的注意力是一种稀缺的资源：\n","此刻你正在阅读本书（而忽略了其他的书），\n","因此你的注意力是用机会成本（与金钱类似）来支付的。\n","为了确保你现在投入的注意力是值得的，\n","我们尽全力（全部的注意力）创作一本好书。\n","\n","自经济学研究稀缺资源分配以来，我们正处在“注意力经济”时代，\n","即人类的注意力被视为可以交换的、有限的、有价值的且稀缺的商品。\n","许多商业模式也被开发出来去利用这一点：\n","在音乐或视频流媒体服务上，我们要么消耗注意力在广告上，要么付钱来隐藏广告；\n","为了在网络游戏世界的成长，我们要么消耗注意力在游戏战斗中，\n","从而帮助吸引新的玩家，要么付钱立即变得强大。\n","总之，注意力不是免费的。\n","\n","注意力是稀缺的，而环境中的干扰注意力的信息却并不少。\n","比如我们的视觉神经系统大约每秒收到$10^8$位的信息，\n","这远远超过了大脑能够完全处理的水平。\n","幸运的是，我们的祖先已经从经验（也称为数据）中认识到\n","“并非感官的所有输入都是一样的”。\n","在整个人类历史中，这种只将注意力引向感兴趣的一小部分信息的能力，\n","使我们的大脑能够更明智地分配资源来生存、成长和社交，\n","例如发现天敌、找寻食物和伴侣。\n","\n","## 生物学中的注意力提示\n","\n","注意力是如何应用于视觉世界中的呢？\n","我们从当今十分普及的*双组件*（two-component）的框架开始讲起：\n","这个框架的出现可以追溯到19世纪90年代的威廉·詹姆斯，\n","他被认为是“美国心理学之父” :cite:`James.2007`。\n","在这个框架中，受试者基于*非自主性提示*和*自主性提示*\n","有选择地引导注意力的焦点。\n","\n","非自主性提示是基于环境中物体的突出性和易见性。\n","想象一下，假如你面前有五个物品：\n","一份报纸、一篇研究论文、一杯咖啡、一本笔记本和一本书，\n","就像 :numref:`fig_eye-coffee`。\n","所有纸制品都是黑白印刷的，但咖啡杯是红色的。\n","换句话说，这个咖啡杯在这种视觉环境中是突出和显眼的，\n","不由自主地引起人们的注意。\n","所以你把视力最敏锐的地方放到咖啡上，\n","如 :numref:`fig_eye-coffee`所示。\n","\n","![由于突出性的非自主性提示（红杯子），注意力不自主地指向了咖啡杯](https://github.com/d2l-ai/d2l-zh-pytorch-colab/blob/master/img/eye-coffee.svg?raw=1)\n",":width:`400px`\n",":label:`fig_eye-coffee`\n","\n","喝咖啡后，你会变得兴奋并想读书。\n","所以你转过头，重新聚焦你的眼睛，然后看看书，\n","就像 :numref:`fig_eye-book`中描述那样。\n","与 :numref:`fig_eye-coffee`中由于突出性导致的选择不同，\n","此时选择书是受到了认知和意识的控制，\n","因此注意力在基于自主性提示去辅助选择时将更为谨慎。\n","受试者的主观意愿推动，选择的力量也就更强大。\n","\n","![依赖于任务的意志提示（想读一本书），注意力被自主引导到书上](https://github.com/d2l-ai/d2l-zh-pytorch-colab/blob/master/img/eye-book.svg?raw=1)\n",":width:`400px`\n",":label:`fig_eye-book`\n","\n","## 查询、键和值\n","\n","自主性的与非自主性的注意力提示解释了人类的注意力的方式，\n","下面我们看看如何通过这两种注意力提示，\n","用神经网络来设计注意力机制的框架，\n","\n","首先，考虑一个相对简单的状况，\n","即只使用非自主性提示。\n","要想将选择偏向于感官输入，\n","我们可以简单地使用参数化的全连接层，\n","甚至是非参数化的最大汇聚层或平均汇聚层。\n","\n","因此，“是否包含自主性提示”将注意力机制与全连接层或汇聚层区别开来。\n","在注意力机制的背景下，我们将自主性提示称为*查询*（query）。\n","给定任何查询，注意力机制通过*注意力汇聚*（attention pooling）\n","将选择引导至*感官输入*（sensory inputs，例如中间特征表示）。\n","在注意力机制中，这些感官输入被称为*值*（value）。\n","更通俗的解释，每个值都与一个*键*（key）配对，\n","这可以想象为感官输入的非自主提示。\n","如 :numref:`fig_qkv`所示，我们可以设计注意力汇聚，\n","以便给定的查询（自主性提示）可以与键（非自主性提示）进行匹配，\n","这将引导得出最匹配的值（感官输入）。\n","\n","![注意力机制通过注意力汇聚将*查询*（自主性提示）和*键*（非自主性提示）结合在一起，实现对*值*（感官输入）的选择倾向](http://d2l.ai/_images/qkv.svg)\n",":label:`fig_qkv`\n","\n","鉴于上面所提框架在 :numref:`fig_qkv`中的主导地位，\n","因此这个框架下的模型将成为本章的中心。\n","然而，注意力机制的设计有许多替代方案。\n","例如，我们可以设计一个不可微的注意力模型，\n","该模型可以使用强化学习方法 :cite:`Mnih.Heess.Graves.ea.2014`进行训练。\n","\n","## 注意力的可视化\n","\n","平均汇聚层可以被视为输入的加权平均值，\n","其中各输入的权重是一样的。\n","实际上，注意力汇聚得到的是加权平均的总和值，\n","其中权重是在给定的查询和不同的键之间计算得出的。\n"]},{"cell_type":"code","execution_count":null,"id":"15c61c25","metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:52:05.826353Z","iopub.status.busy":"2022-07-31T02:52:05.826103Z","iopub.status.idle":"2022-07-31T02:52:07.892688Z","shell.execute_reply":"2022-07-31T02:52:07.891787Z"},"origin_pos":2,"tab":["pytorch"],"id":"15c61c25"},"outputs":[],"source":["import torch\n","from d2l import torch as d2l"]},{"cell_type":"markdown","id":"b5f22e8c","metadata":{"origin_pos":4,"id":"b5f22e8c"},"source":["为了可视化注意力权重，我们定义了`show_heatmaps`函数。\n","其输入`matrices`的形状是\n","（要显示的行数，要显示的列数，查询的数目，键的数目）。\n"]},{"cell_type":"code","execution_count":null,"id":"d8892bf1","metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:52:07.897660Z","iopub.status.busy":"2022-07-31T02:52:07.897036Z","iopub.status.idle":"2022-07-31T02:52:07.907699Z","shell.execute_reply":"2022-07-31T02:52:07.906849Z"},"origin_pos":5,"tab":["pytorch"],"id":"d8892bf1"},"outputs":[],"source":["#@save\n","def show_heatmaps(matrices, xlabel, ylabel, titles=None, figsize=(2.5, 2.5),\n","                  cmap='Reds'):\n","    \"\"\"显示矩阵热图\"\"\"\n","    d2l.use_svg_display()\n","    num_rows, num_cols = matrices.shape[0], matrices.shape[1]\n","    fig, axes = d2l.plt.subplots(num_rows, num_cols, figsize=figsize,\n","                                 sharex=True, sharey=True, squeeze=False)\n","    for i, (row_axes, row_matrices) in enumerate(zip(axes, matrices)):\n","        for j, (ax, matrix) in enumerate(zip(row_axes, row_matrices)):\n","            pcm = ax.imshow(matrix.detach().numpy(), cmap=cmap)\n","            if i == num_rows - 1:\n","                ax.set_xlabel(xlabel)\n","            if j == 0:\n","                ax.set_ylabel(ylabel)\n","            if titles:\n","                ax.set_title(titles[j])\n","    fig.colorbar(pcm, ax=axes, shrink=0.6);"]},{"cell_type":"markdown","id":"b72e8def","metadata":{"origin_pos":6,"id":"b72e8def"},"source":["下面我们使用一个简单的例子进行演示。\n","在本例子中，仅当查询和键相同时，注意力权重为1，否则为0。\n"]},{"cell_type":"code","execution_count":null,"id":"d0d623f0","metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:52:07.910997Z","iopub.status.busy":"2022-07-31T02:52:07.910505Z","iopub.status.idle":"2022-07-31T02:52:08.141637Z","shell.execute_reply":"2022-07-31T02:52:08.141004Z"},"origin_pos":7,"tab":["pytorch"],"id":"d0d623f0","outputId":"dd69d2d1-9dba-411d-d6e1-be897d4d3c2b"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"193.35825pt\" height=\"156.35625pt\" viewBox=\"0 0 193.35825 156.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:52:08.089995</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M -0 156.35625 \n","L 193.35825 156.35625 \n","L 193.35825 0 \n","L -0 0 \n","L -0 156.35625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 118.8 \n","L 145.840625 118.8 \n","L 145.840625 7.2 \n","L 34.240625 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p5bdcf64bcb)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAYAAADG4PRLAAABc0lEQVR4nO3dsW3CUBhGURPRJSNkPxgpA2YAGmqnpfRDMnnXnFO7sHT1N58s+bTeb+vCVK6f35uf/djxPXgBAeMEjBMwTsA4AeMEjBMwTsA4AePO//0C72JkHvu5/25+1gXGCRgnYJyAcQLGCRgnYJyAcQLGCRhnSnvSyDS2LGPz2AgXGCdgnIBxAsYJGCdgnIBxAsYJGCdgnIBxttAHe336tycXGCdgnIBxAsYJGCdgnIBxAsYJGCdg3OGntOI8NsIFxgkYJ2CcgHECxgkYJ2CcgHECxgkYl5zSjj6PjXCBcQLGCRgnYJyAcQLGCRgnYJyAcQLGTTOlmcee4wLjBIwTME7AOAHjBIwTME7AOAHjBIzbbUqb5b8KR+cC4wSMEzBOwDgB4wSMEzBOwDgB4wSMEzBuaAv16d98XGCcgHECxgkYJ2CcgHECxgkYJ2CcgHGny/K1bn3YPDYfFxgnYJyAcQLGCRgnYJyAcQLGCRgnYNwfkEghRAiKZdAAAAAASUVORK5CYII=\" id=\"imageaf42991f35\" transform=\"scale(1 -1)translate(0 -112)\" x=\"34.240625\" y=\"-6.8\" width=\"112\" height=\"112\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m2d4316d516\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m2d4316d516\" x=\"39.820625\" y=\"118.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(36.639375 133.398438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m2d4316d516\" x=\"95.620625\" y=\"118.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 5 -->\n","      <g transform=\"translate(92.439375 133.398438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Keys -->\n","     <g transform=\"translate(78.371094 147.076563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"m1c5f850985\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m1c5f850985\" x=\"34.240625\" y=\"12.78\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 16.579219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m1c5f850985\" x=\"34.240625\" y=\"35.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 2 -->\n","      <g transform=\"translate(20.878125 38.899219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m1c5f850985\" x=\"34.240625\" y=\"57.42\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 4 -->\n","      <g transform=\"translate(20.878125 61.219219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m1c5f850985\" x=\"34.240625\" y=\"79.74\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 6 -->\n","      <g transform=\"translate(20.878125 83.539219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-36\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m1c5f850985\" x=\"34.240625\" y=\"102.06\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 8 -->\n","      <g transform=\"translate(20.878125 105.859219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n","Q 1584 2216 1326 1975 \n","Q 1069 1734 1069 1313 \n","Q 1069 891 1326 650 \n","Q 1584 409 2034 409 \n","Q 2484 409 2743 651 \n","Q 3003 894 3003 1313 \n","Q 3003 1734 2745 1975 \n","Q 2488 2216 2034 2216 \n","z\n","M 1403 2484 \n","Q 997 2584 770 2862 \n","Q 544 3141 544 3541 \n","Q 544 4100 942 4425 \n","Q 1341 4750 2034 4750 \n","Q 2731 4750 3128 4425 \n","Q 3525 4100 3525 3541 \n","Q 3525 3141 3298 2862 \n","Q 3072 2584 2669 2484 \n","Q 3125 2378 3379 2068 \n","Q 3634 1759 3634 1313 \n","Q 3634 634 3220 271 \n","Q 2806 -91 2034 -91 \n","Q 1263 -91 848 271 \n","Q 434 634 434 1313 \n","Q 434 1759 690 2068 \n","Q 947 2378 1403 2484 \n","z\n","M 1172 3481 \n","Q 1172 3119 1398 2916 \n","Q 1625 2713 2034 2713 \n","Q 2441 2713 2670 2916 \n","Q 2900 3119 2900 3481 \n","Q 2900 3844 2670 4047 \n","Q 2441 4250 2034 4250 \n","Q 1625 4250 1398 4047 \n","Q 1172 3844 1172 3481 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-38\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_9\">\n","     <!-- Queries -->\n","     <g transform=\"translate(14.798437 82.307031)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 118.8 \n","L 34.240625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 145.840625 118.8 \n","L 145.840625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 118.8 \n","L 145.840625 118.8 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 7.2 \n","L 145.840625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 152.815625 103.77 \n","L 156.892625 103.77 \n","L 156.892625 22.23 \n","L 152.815625 22.23 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#peb93bf5519)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABRCAYAAAD1sgc6AAAAnklEQVR4nJ2Suw7CQAwEjZT//1QqCnR+0XKzJxmSLqPx7krJo1/Ptq/nsgzbQRVBDqBH4wCkhTtkWDhqR8OSIHjii6H/Z2jtaLD2EDpm3DCkNvldftgB0GJIqM/TBfAfE+AAJcaSpZJRg1Fs0QyCjN5BRA0gkycEmTyRFhox7simsb/blSbGDWCDcdgB4MxwGu8CWAJ4shgqJ9IiBms/jwXJt9gA8G4AAAAASUVORK5CYII=\" id=\"image940399f9a4\" transform=\"scale(1 -1)translate(0 -81)\" x=\"153\" y=\"-22\" width=\"4\" height=\"81\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_8\">\n","      <defs>\n","       <path id=\"mfd6679e0e6\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mfd6679e0e6\" x=\"156.892625\" y=\"103.77\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 0.00 -->\n","      <g transform=\"translate(163.892625 107.569219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_9\">\n","      <g>\n","       <use xlink:href=\"#mfd6679e0e6\" x=\"156.892625\" y=\"83.385\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0.25 -->\n","      <g transform=\"translate(163.892625 87.184219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mfd6679e0e6\" x=\"156.892625\" y=\"63\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0.50 -->\n","      <g transform=\"translate(163.892625 66.799219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#mfd6679e0e6\" x=\"156.892625\" y=\"42.615\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 0.75 -->\n","      <g transform=\"translate(163.892625 46.414219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-37\" d=\"M 525 4666 \n","L 3525 4666 \n","L 3525 4397 \n","L 1831 0 \n","L 1172 0 \n","L 2766 4134 \n","L 525 4134 \n","L 525 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-37\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_10\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#mfd6679e0e6\" x=\"156.892625\" y=\"22.23\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 1.00 -->\n","      <g transform=\"translate(163.892625 26.029219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 152.815625 103.77 \n","L 154.854125 103.77 \n","L 156.892625 103.77 \n","L 156.892625 22.23 \n","L 154.854125 22.23 \n","L 152.815625 22.23 \n","L 152.815625 103.77 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p5bdcf64bcb\">\n","   <rect x=\"34.240625\" y=\"7.2\" width=\"111.6\" height=\"111.6\"/>\n","  </clipPath>\n","  <clipPath id=\"peb93bf5519\">\n","   <rect x=\"152.815625\" y=\"22.23\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["attention_weights = torch.eye(10).reshape((1, 1, 10, 10))\n","show_heatmaps(attention_weights, xlabel='Keys', ylabel='Queries')"]},{"cell_type":"markdown","id":"0ae87cd9","metadata":{"origin_pos":8,"id":"0ae87cd9"},"source":["在后面的章节中，我们将经常调用`show_heatmaps`函数来显示注意力权重。\n","\n","## 小结\n","\n","* 人类的注意力是有限的、有价值和稀缺的资源。\n","* 受试者使用非自主性和自主性提示有选择性地引导注意力。前者基于突出性，后者则依赖于意识。\n","* 注意力机制与全连接层或者汇聚层的区别源于增加的自主提示。\n","* 由于包含了自主性提示，注意力机制与全连接的层或汇聚层不同。\n","* 注意力机制通过注意力汇聚使选择偏向于值（感官输入），其中包含查询（自主性提示）和键（非自主性提示）。键和值是成对的。\n","* 我们可以可视化查询和键之间的注意力权重。\n","\n","## 练习\n","\n","1. 在机器翻译中通过解码序列词元时，其自主性提示可能是什么？非自主性提示和感官输入又是什么？\n","1. 随机生成一个$10 \\times 10$矩阵并使用`softmax`运算来确保每行都是有效的概率分布，然后可视化输出注意力权重。\n"]},{"cell_type":"markdown","id":"97931bad","metadata":{"origin_pos":10,"tab":["pytorch"],"id":"97931bad"},"source":["[Discussions](https://discuss.d2l.ai/t/5764)\n"]},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"90f67a02"},"source":["# 注意力汇聚：Nadaraya-Watson 核回归\n",":label:`sec_nadaraya-watson`\n","\n","上节我们介绍了框架下的注意力机制的主要成分 :numref:`fig_qkv`：\n","查询（自主提示）和键（非自主提示）之间的交互形成了注意力汇聚，\n","注意力汇聚有选择地聚合了值（感官输入）以生成最终的输出。\n","在本节中，我们将介绍注意力汇聚的更多细节，\n","以便从宏观上了解注意力机制在实践中的运作方式。\n","具体来说，1964年提出的Nadaraya-Watson核回归模型\n","是一个简单但完整的例子，可以用于演示具有注意力机制的机器学习。\n"],"id":"90f67a02"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:24.798231Z","iopub.status.busy":"2022-07-31T02:26:24.797699Z","iopub.status.idle":"2022-07-31T02:26:26.679848Z","shell.execute_reply":"2022-07-31T02:26:26.678872Z"},"origin_pos":2,"tab":["pytorch"],"id":"74d68224"},"outputs":[],"source":["import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"74d68224"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"2fc8e236"},"source":["## [**生成数据集**]\n","\n","简单起见，考虑下面这个回归问题：\n","给定的成对的“输入－输出”数据集\n","$\\{(x_1, y_1), \\ldots, (x_n, y_n)\\}$，\n","如何学习$f$来预测任意新输入$x$的输出$\\hat{y} = f(x)$？\n","\n","根据下面的非线性函数生成一个人工数据集，\n","其中加入的噪声项为$\\epsilon$：\n","\n","$$y_i = 2\\sin(x_i) + x_i^{0.8} + \\epsilon,$$\n","\n","其中$\\epsilon$服从均值为$0$和标准差为$0.5$的正态分布。\n","我们生成了$50$个训练样本和$50$个测试样本。\n","为了更好地可视化之后的注意力模式，我们将训练样本进行排序。\n"],"id":"2fc8e236"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:26.683791Z","iopub.status.busy":"2022-07-31T02:26:26.683352Z","iopub.status.idle":"2022-07-31T02:26:26.688829Z","shell.execute_reply":"2022-07-31T02:26:26.688005Z"},"origin_pos":6,"tab":["pytorch"],"id":"cd9b4325"},"outputs":[],"source":["n_train = 50  # 训练样本数\n","x_train, _ = torch.sort(torch.rand(n_train) * 5)   # 排序后的训练样本"],"id":"cd9b4325"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:26.691872Z","iopub.status.busy":"2022-07-31T02:26:26.691499Z","iopub.status.idle":"2022-07-31T02:26:26.702135Z","shell.execute_reply":"2022-07-31T02:26:26.701290Z"},"origin_pos":9,"tab":["pytorch"],"id":"dbd1af96","outputId":"7fa547a0-988c-43a2-c3d6-6ecbabf5b8f4"},"outputs":[{"data":{"text/plain":["50"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["def f(x):\n","    return 2 * torch.sin(x) + x**0.8\n","\n","y_train = f(x_train) + torch.normal(0.0, 0.5, (n_train,))  # 训练样本的输出\n","x_test = torch.arange(0, 5, 0.1)  # 测试样本\n","y_truth = f(x_test)  # 测试样本的真实输出\n","n_test = len(x_test)  # 测试样本数\n","n_test"],"id":"dbd1af96"},{"cell_type":"markdown","metadata":{"origin_pos":11,"id":"9af9a757"},"source":["下面的函数将绘制所有的训练样本（样本由圆圈表示），\n","不带噪声项的真实数据生成函数$f$（标记为“Truth”），\n","以及学习得到的预测函数（标记为“Pred”）。\n"],"id":"9af9a757"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:26.705198Z","iopub.status.busy":"2022-07-31T02:26:26.704825Z","iopub.status.idle":"2022-07-31T02:26:26.709584Z","shell.execute_reply":"2022-07-31T02:26:26.708764Z"},"origin_pos":12,"tab":["pytorch"],"id":"5d78961a"},"outputs":[],"source":["def plot_kernel_reg(y_hat):\n","    d2l.plot(x_test, [y_truth, y_hat], 'x', 'y', legend=['Truth', 'Pred'],\n","             xlim=[0, 5], ylim=[-1, 5])\n","    d2l.plt.plot(x_train, y_train, 'o', alpha=0.5);"],"id":"5d78961a"},{"cell_type":"markdown","metadata":{"origin_pos":13,"id":"4e6291ce"},"source":["## 平均汇聚\n","\n","我们先使用最简单的估计器来解决回归问题：\n","基于平均汇聚来计算所有训练样本输出值的平均值：\n","\n","$$f(x) = \\frac{1}{n}\\sum_{i=1}^n y_i,$$\n",":eqlabel:`eq_avg-pooling`\n","\n","如下图所示，这个估计器确实不够聪明：\n","真实函数$f$（“Truth”）和预测函数（“Pred”）相差很大。\n"],"id":"4e6291ce"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:26.712756Z","iopub.status.busy":"2022-07-31T02:26:26.712155Z","iopub.status.idle":"2022-07-31T02:26:26.908118Z","shell.execute_reply":"2022-07-31T02:26:26.907195Z"},"origin_pos":15,"tab":["pytorch"],"id":"974ba5d1","outputId":"4e3b726e-27af-4a81-82d6-75f3b29c4d52"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"184.455469pt\" viewBox=\"0 0 248.301563 184.455469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:26.858471</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 184.455469 \n","L 248.301563 184.455469 \n","L 248.301563 -0 \n","L 0 -0 \n","L 0 184.455469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","L 237.920313 10.999219 \n","L 42.620312 10.999219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"mebb6231275\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(39.439062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 81.680312 146.899219 \n","L 81.680312 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"81.680312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 1 -->\n","      <g transform=\"translate(78.499062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 120.740313 146.899219 \n","L 120.740313 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"120.740313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 2 -->\n","      <g transform=\"translate(117.559062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 159.800313 146.899219 \n","L 159.800313 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"159.800313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 3 -->\n","      <g transform=\"translate(156.619063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 198.860313 146.899219 \n","L 198.860313 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"198.860313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 4 -->\n","      <g transform=\"translate(195.679063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#mebb6231275\" x=\"237.920313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 5 -->\n","      <g transform=\"translate(234.739063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_7\">\n","     <!-- x -->\n","     <g transform=\"translate(137.310937 175.175781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n","L 2247 1797 \n","L 3578 0 \n","L 2900 0 \n","L 1881 1375 \n","L 863 0 \n","L 184 0 \n","L 1544 1831 \n","L 300 3500 \n","L 978 3500 \n","L 1906 2253 \n","L 2834 3500 \n","L 3513 3500 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-78\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <defs>\n","       <path id=\"ma1c2239ce7\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- −1 -->\n","      <g transform=\"translate(20.878125 150.698437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n","L 4684 2272 \n","L 4684 1741 \n","L 678 1741 \n","L 678 2272 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 42.620312 124.249219 \n","L 237.920313 124.249219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"124.249219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0 -->\n","      <g transform=\"translate(29.257812 128.048437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 42.620312 101.599219 \n","L 237.920313 101.599219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"101.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 1 -->\n","      <g transform=\"translate(29.257812 105.398437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_19\">\n","      <path d=\"M 42.620312 78.949219 \n","L 237.920313 78.949219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"78.949219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 2 -->\n","      <g transform=\"translate(29.257812 82.748437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_21\">\n","      <path d=\"M 42.620312 56.299219 \n","L 237.920313 56.299219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"56.299219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 3 -->\n","      <g transform=\"translate(29.257812 60.098437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_23\">\n","      <path d=\"M 42.620312 33.649219 \n","L 237.920313 33.649219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"33.649219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 4 -->\n","      <g transform=\"translate(29.257812 37.448437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_25\">\n","      <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#ma1c2239ce7\" x=\"42.620312\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 5 -->\n","      <g transform=\"translate(29.257812 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_15\">\n","     <!-- y -->\n","     <g transform=\"translate(14.798437 81.908594)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-79\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_27\">\n","    <path d=\"M 42.620312 124.249219 \n","L 46.526313 116.136982 \n","L 50.432313 108.999323 \n","L 54.338313 102.217148 \n","L 58.244313 95.726379 \n","L 62.150312 89.522233 \n","L 66.056313 83.619087 \n","L 69.962312 78.038824 \n","L 73.868313 72.806 \n","L 77.774314 67.945395 \n","L 81.680312 63.480584 \n","L 85.586313 59.432954 \n","L 89.492314 55.821098 \n","L 93.398311 52.660258 \n","L 97.304312 49.962036 \n","L 101.210313 47.734078 \n","L 105.116313 45.979911 \n","L 109.022314 44.69881 \n","L 112.928315 43.885737 \n","L 116.834312 43.531371 \n","L 120.740313 43.622105 \n","L 124.646309 44.140188 \n","L 128.552314 45.063873 \n","L 132.458311 46.367563 \n","L 136.364316 48.022135 \n","L 140.270312 49.995107 \n","L 144.176318 52.251038 \n","L 148.082314 54.751808 \n","L 151.98832 57.457039 \n","L 155.894316 60.324422 \n","L 159.800313 63.310193 \n","L 163.706318 66.369546 \n","L 167.612314 69.45704 \n","L 171.518311 72.527086 \n","L 175.424316 75.534393 \n","L 179.330312 78.434371 \n","L 183.236318 81.183652 \n","L 187.142314 83.740416 \n","L 191.048311 86.06491 \n","L 194.954316 88.119776 \n","L 198.860313 89.870412 \n","L 202.766309 91.285368 \n","L 206.672305 92.336626 \n","L 210.57832 92.999866 \n","L 214.484316 93.254719 \n","L 218.390312 93.084986 \n","L 222.296309 92.478756 \n","L 226.202305 91.428572 \n","L 230.10832 89.931453 \n","L 234.014316 87.988973 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"line2d_28\">\n","    <path d=\"M 42.620312 74.514309 \n","L 46.526313 74.514309 \n","L 50.432313 74.514309 \n","L 54.338313 74.514309 \n","L 58.244313 74.514309 \n","L 62.150312 74.514309 \n","L 66.056313 74.514309 \n","L 69.962312 74.514309 \n","L 73.868313 74.514309 \n","L 77.774314 74.514309 \n","L 81.680312 74.514309 \n","L 85.586313 74.514309 \n","L 89.492314 74.514309 \n","L 93.398311 74.514309 \n","L 97.304312 74.514309 \n","L 101.210313 74.514309 \n","L 105.116313 74.514309 \n","L 109.022314 74.514309 \n","L 112.928315 74.514309 \n","L 116.834312 74.514309 \n","L 120.740313 74.514309 \n","L 124.646309 74.514309 \n","L 128.552314 74.514309 \n","L 132.458311 74.514309 \n","L 136.364316 74.514309 \n","L 140.270312 74.514309 \n","L 144.176318 74.514309 \n","L 148.082314 74.514309 \n","L 151.98832 74.514309 \n","L 155.894316 74.514309 \n","L 159.800313 74.514309 \n","L 163.706318 74.514309 \n","L 167.612314 74.514309 \n","L 171.518311 74.514309 \n","L 175.424316 74.514309 \n","L 179.330312 74.514309 \n","L 183.236318 74.514309 \n","L 187.142314 74.514309 \n","L 191.048311 74.514309 \n","L 194.954316 74.514309 \n","L 198.860313 74.514309 \n","L 202.766309 74.514309 \n","L 206.672305 74.514309 \n","L 210.57832 74.514309 \n","L 214.484316 74.514309 \n","L 218.390312 74.514309 \n","L 222.296309 74.514309 \n","L 226.202305 74.514309 \n","L 230.10832 74.514309 \n","L 234.014316 74.514309 \n","\" clip-path=\"url(#p31940976c8)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"line2d_29\">\n","    <defs>\n","     <path id=\"m3af572a361\" d=\"M 0 3 \n","C 0.795609 3 1.55874 2.683901 2.12132 2.12132 \n","C 2.683901 1.55874 3 0.795609 3 0 \n","C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \n","C 1.55874 -2.683901 0.795609 -3 0 -3 \n","C -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \n","C -2.683901 -1.55874 -3 -0.795609 -3 0 \n","C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \n","C -1.55874 2.683901 -0.795609 3 0 3 \n","z\n","\" style=\"stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </defs>\n","    <g clip-path=\"url(#p31940976c8)\">\n","     <use xlink:href=\"#m3af572a361\" x=\"44.707936\" y=\"125.985601\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"49.333159\" y=\"103.170939\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"60.036688\" y=\"105.931758\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"62.900252\" y=\"89.437088\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"63.599851\" y=\"79.591613\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"71.181077\" y=\"79.555681\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"71.282072\" y=\"77.053631\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"77.419072\" y=\"66.872935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"89.621611\" y=\"90.736426\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"93.643908\" y=\"56.317412\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"93.720667\" y=\"42.085824\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"106.709574\" y=\"46.449608\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"109.919949\" y=\"39.62002\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"115.89625\" y=\"56.959304\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"122.842639\" y=\"38.21161\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"128.205093\" y=\"50.21983\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"132.63648\" y=\"49.415921\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"139.87121\" y=\"44.880142\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"140.663156\" y=\"51.174561\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"141.536476\" y=\"55.449425\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"144.634723\" y=\"41.94644\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"144.830111\" y=\"38.233875\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"150.066007\" y=\"65.603482\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"152.379339\" y=\"51.619989\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"159.657298\" y=\"39.76906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"161.33007\" y=\"76.584841\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"166.84419\" y=\"78.888202\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"167.057738\" y=\"77.713809\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"174.818409\" y=\"72.789805\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"174.926379\" y=\"66.252119\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"175.244787\" y=\"85.023226\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"177.112919\" y=\"91.666709\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"178.537659\" y=\"90.531084\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"183.587898\" y=\"75.135897\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"184.210875\" y=\"80.267727\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"185.439528\" y=\"81.906104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"185.855635\" y=\"89.10104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"189.699432\" y=\"87.132267\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"191.165836\" y=\"88.740108\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"193.231666\" y=\"91.45634\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"196.150943\" y=\"86.942672\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"198.969643\" y=\"92.356445\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"208.728422\" y=\"71.578922\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"219.230498\" y=\"97.103015\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"226.081464\" y=\"113.938906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"227.570982\" y=\"76.711935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"231.923743\" y=\"100.46935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"232.112565\" y=\"99.46274\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"236.255084\" y=\"91.129232\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#m3af572a361\" x=\"237.390778\" y=\"76.54076\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"legend_1\">\n","    <g id=\"patch_7\">\n","     <path d=\"M 173.58125 48.355469 \n","L 230.920313 48.355469 \n","Q 232.920313 48.355469 232.920313 46.355469 \n","L 232.920313 17.999219 \n","Q 232.920313 15.999219 230.920313 15.999219 \n","L 173.58125 15.999219 \n","Q 171.58125 15.999219 171.58125 17.999219 \n","L 171.58125 46.355469 \n","Q 171.58125 48.355469 173.58125 48.355469 \n","z\n","\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n","    </g>\n","    <g id=\"line2d_30\">\n","     <path d=\"M 175.58125 24.097656 \n","L 185.58125 24.097656 \n","L 195.58125 24.097656 \n","\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","    </g>\n","    <g id=\"text_16\">\n","     <!-- Truth -->\n","     <g transform=\"translate(203.58125 27.597656)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-54\" d=\"M -19 4666 \n","L 3928 4666 \n","L 3928 4134 \n","L 2272 4134 \n","L 2272 0 \n","L 1638 0 \n","L 1638 4134 \n","L -19 4134 \n","L -19 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-54\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_31\">\n","     <path d=\"M 175.58125 38.775781 \n","L 185.58125 38.775781 \n","L 195.58125 38.775781 \n","\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Pred -->\n","     <g transform=\"translate(203.58125 42.275781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \n","L 1259 2394 \n","L 2053 2394 \n","Q 2494 2394 2734 2622 \n","Q 2975 2850 2975 3272 \n","Q 2975 3691 2734 3919 \n","Q 2494 4147 2053 4147 \n","L 1259 4147 \n","z\n","M 628 4666 \n","L 2053 4666 \n","Q 2838 4666 3239 4311 \n","Q 3641 3956 3641 3272 \n","Q 3641 2581 3239 2228 \n","Q 2838 1875 2053 1875 \n","L 1259 1875 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-50\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n","     </g>\n","    </g>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p31940976c8\">\n","   <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["y_hat = torch.repeat_interleave(y_train.mean(), n_test)\n","plot_kernel_reg(y_hat)"],"id":"974ba5d1"},{"cell_type":"markdown","metadata":{"origin_pos":17,"id":"85028ade"},"source":["## [**非参数注意力汇聚**]\n","\n","显然，平均汇聚忽略了输入$x_i$。\n","于是Nadaraya :cite:`Nadaraya.1964`和\n","Watson :cite:`Watson.1964`提出了一个更好的想法，\n","根据输入的位置对输出$y_i$进行加权：\n","\n","$$f(x) = \\sum_{i=1}^n \\frac{K(x - x_i)}{\\sum_{j=1}^n K(x - x_j)} y_i,$$\n",":eqlabel:`eq_nadaraya-watson`\n","\n","其中$K$是*核*（kernel）。\n","公式 :eqref:`eq_nadaraya-watson`所描述的估计器被称为\n","*Nadaraya-Watson核回归*（Nadaraya-Watson kernel regression）。\n","这里我们不会深入讨论核函数的细节，\n","但受此启发，\n","我们可以从 :numref:`fig_qkv`中的注意力机制框架的角度\n","重写 :eqref:`eq_nadaraya-watson`，\n","成为一个更加通用的*注意力汇聚*（attention pooling）公式：\n","\n","$$f(x) = \\sum_{i=1}^n \\alpha(x, x_i) y_i,$$\n",":eqlabel:`eq_attn-pooling`\n","\n","其中$x$是查询，$(x_i, y_i)$是键值对。\n","比较 :eqref:`eq_attn-pooling`和 :eqref:`eq_avg-pooling`，\n","注意力汇聚是$y_i$的加权平均。\n","将查询$x$和键$x_i$之间的关系建模为\n","*注意力权重*（attention weight）$\\alpha(x, x_i)$，\n","如 :eqref:`eq_attn-pooling`所示，\n","这个权重将被分配给每一个对应值$y_i$。\n","对于任何查询，模型在所有键值对注意力权重都是一个有效的概率分布：\n","它们是非负的，并且总和为1。\n","\n","为了更好地理解注意力汇聚，\n","我们考虑一个*高斯核*（Gaussian kernel），其定义为：\n","\n","$$K(u) = \\frac{1}{\\sqrt{2\\pi}} \\exp(-\\frac{u^2}{2}).$$\n","\n","将高斯核代入 :eqref:`eq_attn-pooling`和\n"," :eqref:`eq_nadaraya-watson`可以得到：\n","\n","$$\\begin{aligned} f(x) &=\\sum_{i=1}^n \\alpha(x, x_i) y_i\\\\ &= \\sum_{i=1}^n \\frac{\\exp\\left(-\\frac{1}{2}(x - x_i)^2\\right)}{\\sum_{j=1}^n \\exp\\left(-\\frac{1}{2}(x - x_j)^2\\right)} y_i \\\\&= \\sum_{i=1}^n \\mathrm{softmax}\\left(-\\frac{1}{2}(x - x_i)^2\\right) y_i. \\end{aligned}$$\n",":eqlabel:`eq_nadaraya-watson-gaussian`\n","\n","在 :eqref:`eq_nadaraya-watson-gaussian`中，\n","如果一个键$x_i$越是接近给定的查询$x$，\n","那么分配给这个键对应值$y_i$的注意力权重就会越大，\n","也就“获得了更多的注意力”。\n","\n","值得注意的是，Nadaraya-Watson核回归是一个非参数模型。\n","因此， :eqref:`eq_nadaraya-watson-gaussian`是\n","*非参数的注意力汇聚*（nonparametric attention pooling）模型。\n","接下来，我们将基于这个非参数的注意力汇聚模型来绘制预测结果。\n","你会发现新的模型预测线是平滑的，并且比平均汇聚的预测更接近真实。\n"],"id":"85028ade"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:26.913009Z","iopub.status.busy":"2022-07-31T02:26:26.912764Z","iopub.status.idle":"2022-07-31T02:26:27.095384Z","shell.execute_reply":"2022-07-31T02:26:27.094431Z"},"origin_pos":19,"tab":["pytorch"],"id":"c2adcc3b","outputId":"3b90063b-dcac-42fb-8c00-1aaf91f378f2"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"184.455469pt\" viewBox=\"0 0 248.301563 184.455469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:27.044405</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 184.455469 \n","L 248.301563 184.455469 \n","L 248.301563 -0 \n","L 0 -0 \n","L 0 184.455469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","L 237.920313 10.999219 \n","L 42.620312 10.999219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"m907eea1863\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(39.439062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 81.680312 146.899219 \n","L 81.680312 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"81.680312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 1 -->\n","      <g transform=\"translate(78.499062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 120.740313 146.899219 \n","L 120.740313 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"120.740313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 2 -->\n","      <g transform=\"translate(117.559062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 159.800313 146.899219 \n","L 159.800313 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"159.800313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 3 -->\n","      <g transform=\"translate(156.619063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 198.860313 146.899219 \n","L 198.860313 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"198.860313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 4 -->\n","      <g transform=\"translate(195.679063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m907eea1863\" x=\"237.920313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 5 -->\n","      <g transform=\"translate(234.739063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_7\">\n","     <!-- x -->\n","     <g transform=\"translate(137.310937 175.175781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n","L 2247 1797 \n","L 3578 0 \n","L 2900 0 \n","L 1881 1375 \n","L 863 0 \n","L 184 0 \n","L 1544 1831 \n","L 300 3500 \n","L 978 3500 \n","L 1906 2253 \n","L 2834 3500 \n","L 3513 3500 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-78\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <defs>\n","       <path id=\"m23ded5a005\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- −1 -->\n","      <g transform=\"translate(20.878125 150.698437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n","L 4684 2272 \n","L 4684 1741 \n","L 678 1741 \n","L 678 2272 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 42.620312 124.249219 \n","L 237.920313 124.249219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"124.249219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0 -->\n","      <g transform=\"translate(29.257812 128.048437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 42.620312 101.599219 \n","L 237.920313 101.599219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"101.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 1 -->\n","      <g transform=\"translate(29.257812 105.398437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_19\">\n","      <path d=\"M 42.620312 78.949219 \n","L 237.920313 78.949219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"78.949219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 2 -->\n","      <g transform=\"translate(29.257812 82.748437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_21\">\n","      <path d=\"M 42.620312 56.299219 \n","L 237.920313 56.299219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"56.299219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 3 -->\n","      <g transform=\"translate(29.257812 60.098437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_23\">\n","      <path d=\"M 42.620312 33.649219 \n","L 237.920313 33.649219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"33.649219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 4 -->\n","      <g transform=\"translate(29.257812 37.448437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_25\">\n","      <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#m23ded5a005\" x=\"42.620312\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 5 -->\n","      <g transform=\"translate(29.257812 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_15\">\n","     <!-- y -->\n","     <g transform=\"translate(14.798437 81.908594)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-79\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_27\">\n","    <path d=\"M 42.620312 124.249219 \n","L 46.526313 116.136982 \n","L 50.432313 108.999323 \n","L 54.338313 102.217148 \n","L 58.244313 95.726379 \n","L 62.150312 89.522233 \n","L 66.056313 83.619087 \n","L 69.962312 78.038824 \n","L 73.868313 72.806 \n","L 77.774314 67.945395 \n","L 81.680312 63.480584 \n","L 85.586313 59.432954 \n","L 89.492314 55.821098 \n","L 93.398311 52.660258 \n","L 97.304312 49.962036 \n","L 101.210313 47.734078 \n","L 105.116313 45.979911 \n","L 109.022314 44.69881 \n","L 112.928315 43.885737 \n","L 116.834312 43.531371 \n","L 120.740313 43.622105 \n","L 124.646309 44.140188 \n","L 128.552314 45.063873 \n","L 132.458311 46.367563 \n","L 136.364316 48.022135 \n","L 140.270312 49.995107 \n","L 144.176318 52.251038 \n","L 148.082314 54.751808 \n","L 151.98832 57.457039 \n","L 155.894316 60.324422 \n","L 159.800313 63.310193 \n","L 163.706318 66.369546 \n","L 167.612314 69.45704 \n","L 171.518311 72.527086 \n","L 175.424316 75.534393 \n","L 179.330312 78.434371 \n","L 183.236318 81.183652 \n","L 187.142314 83.740416 \n","L 191.048311 86.06491 \n","L 194.954316 88.119776 \n","L 198.860313 89.870412 \n","L 202.766309 91.285368 \n","L 206.672305 92.336626 \n","L 210.57832 92.999866 \n","L 214.484316 93.254719 \n","L 218.390312 93.084986 \n","L 222.296309 92.478756 \n","L 226.202305 91.428572 \n","L 230.10832 89.931453 \n","L 234.014316 87.988973 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"line2d_28\">\n","    <path d=\"M 42.620312 82.995896 \n","L 46.526313 81.715334 \n","L 50.432313 80.393189 \n","L 54.338313 79.033019 \n","L 58.244313 77.640037 \n","L 62.150312 76.221382 \n","L 66.056313 74.786381 \n","L 69.962312 73.346639 \n","L 73.868313 71.916083 \n","L 77.774314 70.510918 \n","L 81.680312 69.149327 \n","L 85.586313 67.850994 \n","L 89.492314 66.636439 \n","L 93.398311 65.526178 \n","L 97.304312 64.539797 \n","L 101.210313 63.694918 \n","L 105.116313 63.006254 \n","L 109.022314 62.484877 \n","L 112.928315 62.137592 \n","L 116.834312 61.966687 \n","L 120.740313 61.970024 \n","L 124.646309 62.141275 \n","L 128.552314 62.470545 \n","L 132.458311 62.945092 \n","L 136.364316 63.550063 \n","L 140.270312 64.269346 \n","L 144.176318 65.086253 \n","L 148.082314 65.984195 \n","L 151.98832 66.947144 \n","L 155.894316 67.960056 \n","L 159.800313 69.009068 \n","L 163.706318 70.08169 \n","L 167.612314 71.166835 \n","L 171.518311 72.254782 \n","L 175.424316 73.337178 \n","L 179.330312 74.406857 \n","L 183.236318 75.457807 \n","L 187.142314 76.484976 \n","L 191.048311 77.484204 \n","L 194.954316 78.452046 \n","L 198.860313 79.385715 \n","L 202.766309 80.283007 \n","L 206.672305 81.142146 \n","L 210.57832 81.961785 \n","L 214.484316 82.740945 \n","L 218.390312 83.47895 \n","L 222.296309 84.175427 \n","L 226.202305 84.830302 \n","L 230.10832 85.443725 \n","L 234.014316 86.016103 \n","\" clip-path=\"url(#pe4f26a3888)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"line2d_29\">\n","    <defs>\n","     <path id=\"madca525805\" d=\"M 0 3 \n","C 0.795609 3 1.55874 2.683901 2.12132 2.12132 \n","C 2.683901 1.55874 3 0.795609 3 0 \n","C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \n","C 1.55874 -2.683901 0.795609 -3 0 -3 \n","C -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \n","C -2.683901 -1.55874 -3 -0.795609 -3 0 \n","C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \n","C -1.55874 2.683901 -0.795609 3 0 3 \n","z\n","\" style=\"stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </defs>\n","    <g clip-path=\"url(#pe4f26a3888)\">\n","     <use xlink:href=\"#madca525805\" x=\"44.707936\" y=\"125.985601\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"49.333159\" y=\"103.170939\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"60.036688\" y=\"105.931758\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"62.900252\" y=\"89.437088\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"63.599851\" y=\"79.591613\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"71.181077\" y=\"79.555681\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"71.282072\" y=\"77.053631\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"77.419072\" y=\"66.872935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"89.621611\" y=\"90.736426\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"93.643908\" y=\"56.317412\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"93.720667\" y=\"42.085824\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"106.709574\" y=\"46.449608\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"109.919949\" y=\"39.62002\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"115.89625\" y=\"56.959304\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"122.842639\" y=\"38.21161\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"128.205093\" y=\"50.21983\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"132.63648\" y=\"49.415921\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"139.87121\" y=\"44.880142\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"140.663156\" y=\"51.174561\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"141.536476\" y=\"55.449425\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"144.634723\" y=\"41.94644\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"144.830111\" y=\"38.233875\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"150.066007\" y=\"65.603482\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"152.379339\" y=\"51.619989\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"159.657298\" y=\"39.76906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"161.33007\" y=\"76.584841\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"166.84419\" y=\"78.888202\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"167.057738\" y=\"77.713809\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"174.818409\" y=\"72.789805\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"174.926379\" y=\"66.252119\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"175.244787\" y=\"85.023226\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"177.112919\" y=\"91.666709\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"178.537659\" y=\"90.531084\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"183.587898\" y=\"75.135897\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"184.210875\" y=\"80.267727\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"185.439528\" y=\"81.906104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"185.855635\" y=\"89.10104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"189.699432\" y=\"87.132267\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"191.165836\" y=\"88.740108\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"193.231666\" y=\"91.45634\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"196.150943\" y=\"86.942672\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"198.969643\" y=\"92.356445\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"208.728422\" y=\"71.578922\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"219.230498\" y=\"97.103015\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"226.081464\" y=\"113.938906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"227.570982\" y=\"76.711935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"231.923743\" y=\"100.46935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"232.112565\" y=\"99.46274\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"236.255084\" y=\"91.129232\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#madca525805\" x=\"237.390778\" y=\"76.54076\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"legend_1\">\n","    <g id=\"patch_7\">\n","     <path d=\"M 173.58125 48.355469 \n","L 230.920313 48.355469 \n","Q 232.920313 48.355469 232.920313 46.355469 \n","L 232.920313 17.999219 \n","Q 232.920313 15.999219 230.920313 15.999219 \n","L 173.58125 15.999219 \n","Q 171.58125 15.999219 171.58125 17.999219 \n","L 171.58125 46.355469 \n","Q 171.58125 48.355469 173.58125 48.355469 \n","z\n","\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n","    </g>\n","    <g id=\"line2d_30\">\n","     <path d=\"M 175.58125 24.097656 \n","L 185.58125 24.097656 \n","L 195.58125 24.097656 \n","\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","    </g>\n","    <g id=\"text_16\">\n","     <!-- Truth -->\n","     <g transform=\"translate(203.58125 27.597656)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-54\" d=\"M -19 4666 \n","L 3928 4666 \n","L 3928 4134 \n","L 2272 4134 \n","L 2272 0 \n","L 1638 0 \n","L 1638 4134 \n","L -19 4134 \n","L -19 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-54\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_31\">\n","     <path d=\"M 175.58125 38.775781 \n","L 185.58125 38.775781 \n","L 195.58125 38.775781 \n","\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Pred -->\n","     <g transform=\"translate(203.58125 42.275781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \n","L 1259 2394 \n","L 2053 2394 \n","Q 2494 2394 2734 2622 \n","Q 2975 2850 2975 3272 \n","Q 2975 3691 2734 3919 \n","Q 2494 4147 2053 4147 \n","L 1259 4147 \n","z\n","M 628 4666 \n","L 2053 4666 \n","Q 2838 4666 3239 4311 \n","Q 3641 3956 3641 3272 \n","Q 3641 2581 3239 2228 \n","Q 2838 1875 2053 1875 \n","L 1259 1875 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-50\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n","     </g>\n","    </g>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"pe4f26a3888\">\n","   <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# X_repeat的形状:(n_test,n_train),\n","# 每一行都包含着相同的测试输入（例如：同样的查询）\n","X_repeat = x_test.repeat_interleave(n_train).reshape((-1, n_train))\n","# x_train包含着键。attention_weights的形状：(n_test,n_train),\n","# 每一行都包含着要在给定的每个查询的值（y_train）之间分配的注意力权重\n","attention_weights = nn.functional.softmax(-(X_repeat - x_train)**2 / 2, dim=1)\n","# y_hat的每个元素都是值的加权平均值，其中的权重是注意力权重\n","y_hat = torch.matmul(attention_weights, y_train)\n","plot_kernel_reg(y_hat)"],"id":"c2adcc3b"},{"cell_type":"markdown","metadata":{"origin_pos":21,"id":"379ad18b"},"source":["现在，我们来观察注意力的权重。\n","这里测试数据的输入相当于查询，而训练数据的输入相当于键。\n","因为两个输入都是经过排序的，因此由观察可知“查询-键”对越接近，\n","注意力汇聚的[**注意力权重**]就越高。\n"],"id":"379ad18b"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.099126Z","iopub.status.busy":"2022-07-31T02:26:27.098616Z","iopub.status.idle":"2022-07-31T02:26:27.280986Z","shell.execute_reply":"2022-07-31T02:26:27.280271Z"},"origin_pos":23,"tab":["pytorch"],"id":"d7bf28ed","outputId":"48890adb-e1c3-4036-8987-ea3878d65855"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"199.72075pt\" height=\"159.039469pt\" viewBox=\"0 0 199.72075 159.039469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:27.230010</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 159.039469 \n","L 199.72075 159.039469 \n","L 199.72075 0 \n","L 0 0 \n","L 0 159.039469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 40.603125 121.483219 \n","L 152.203125 121.483219 \n","L 152.203125 9.883219 \n","L 40.603125 9.883219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pa2aa0c36fb)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAYAAADG4PRLAAAekUlEQVR4nN1dXZPjOI5MUnLtxcb9/x95D7cbN9NdZX2Q90CCTICgrOqp7plZdlTblihZJpxAJgjKIX/7d8YvbDlnfiFP+mvZlhPtpz4AkJI+aTrL/pxLt3QC6aivS9987MB59GO2D+T339v+fq56TDrL43mW5x/fy3Ppf576Ws8TeH6UazuOfo7zBI4Ded/Kvn0Htg3417+Ajw8c//6O8/sT+TiRtwM5yTnrtbxo68sef4nmGf0zh+d7xyX6Ig3HJ/26PU9jX3u+Fy3E0D5hiKEYMQCIQZ9HXlP7pQbM7iB6gyYD7hjObuf+GXVAc0UpP1YkSRN0eIZJR0cYIynX88l2eW3Pl6mPIFj6JvIsMSI8IsKxIIaAvERldDteIZABqzF/mQEH43nGVMZxUOO6X3TjwRiZH3Pqg82GAXwUcR82ljVeM7r0z7oPf/H4dQhACAhLRFhi77P0yxjwJgYkJP4SA86N58Q++3owdHb61/8Ebc1YpV+W/oxARou9roaaaoST0ZX18UAxWjq7EcWQKfVrsXGbDbhGgA05ayEAMYCB+OfHQM91XrnLtt8cRwZj5GUZxNNxoenUA9vQdHb0iXHkHExcxGDtuoy7zfQFGj4rikGWiPBYyrmWMO5HiYvyOsQAtuCfb0BgbqhXMdBu40Gz7s6gLQuyAMeFJo2oxOcm1DEi2Z3yeeT67L4YSwyMgj50BgoMhgJQEBpCOTb84hjYGrtPl+2JgWZuNI/sLpsBbrGLBvncNYKOvSPLNkaRIFfcKDDGt8TIS9QvjwjnGBgjsK4t1gWgbJNGhgIALEtzvdLvpxvQ130w2/JoWJf62232y+AYnAeR3Z96NO/DRATosUyOaTF1crx3DbaJIUIohpFtvH9Z9DExaiPiVyLQHXhnvzKeZxBo1DQ2aFzleWjWeBzI596PO/fuJtV1EHHh2MlxDRjdL5McYr1D/GOjMYINstpzi8g/zYBe89A37OfXMP1pBxk8D5SfmCGfm0mIOh19Ifg6BpdI8dDbf9WswcRdhk5YmrGkrWs36i81oMc0x04aeTmRPa07cga2DXjuDJPISLZCnqUCNzGqEvL0N0OgMFp1LXSNIfTnYoR17UZfltGY69qPBUofcau/KgbqNkGOKyVMf+ti3W2WzBDKFOWfoLLtM+ewiOa+fB3203myQQwZY3kUFLIBieAoBArp+Zkkxk+XAdfu0RAXa4yhn0P7QdKhabxskFhRo1ijc72sGc/ToJGIEJOiRNc6HYPaOA6KgRz3iMdDGTAsC7Csv9iFssuT11M0ecaboQ1qALXxugvMzYBHd3uAzk+qa4XjDgmtVri3Yw2zncXCGMs+QaAYUdwjxcKwrkAgErOuwPooz0MAQvxaA87R1zrwC99oTjZFH2sMK/vEeIMGNPlJ6Z+yNigbg40nx86Md3PGYXCFwkIFdcui3WMIxViN1PQ+CD8BgZ82Hm8f/kAuyuursx45kYusz7OaHcgk3Allds6RdZ0Y1yYEgNF4LGFss9pOmpCRirywrto9hgg83vQU0voofYCy/asROG05j8+VcRhx9rU9lrfxACbf7VkyYgW5dXW2D/BCOtyUDeI6gRGNIQCxutAQm3EGGcE68Nex0IkBZqRFEtMvEKgQn053FryTl/p4sJB35gN538A+Hbd5ZbwYEUTIswwwnio8Kqre3oDl0Y0XQkegxMGfHQNb89zpFTtVrtMgk4+t+9r0EJ/bRZ1FpXMMt1k8U/HRMd5F+Agh+HJCHhl5jC5mqU0fLuUP+Iku9NJ4FnGEsuY6mUAUecDnKbMIVNuSU49vFVH51K9bTGPScp6YZmJ4/o4JjGdg/rwhln5t4rUMfEh9W85ZE5XHW0HW400jTvZxPnR9kLgvfb7EgC8JTOk1GrIcPHet1E/lFO23X1H9szPMIQaaWGZROX4w38BXAl6MyI3iX/DQJ39iHEHk+tAkRhD4M1jodCCmccwQF55NlzjHqSseNEX/s4qBLWWWjAEtAtU1mDbIiOS7Tk6PcWvajframQWRCIy+x1vv67HQ5fGrhLz5UJZ5enrPpMGaNFDHk1hv507ddYrbTExgcn/Og81FSsPlT5D3qgm65H1YhNt+gj5xi0JQ2IWykJdj1sfXInB0ny+Mp7YT+izdZ/3F57G1KYDRfbmnwhIZm+f0AIqx3rUS23zlZq3ReJvXmKDEmhpbHzq+NVKjU2lFBz4UM/1iBBrW2DbreDYkmi15YTnA55N9hyYxHXn0x8YE9PkAnbukc+n9njCPY19As0WvcUYlVnTFxXehkVyoSaWFRWdn/pABNfomxhP32A/S+zxNaOOTFd+WxKiktdFtKv3F12HEOrc76TGPrFwhTwwh6GECI+6xSYSaExVDtlMYGYEfQKDLOF8yuYkhmmDvmq2REJEGfFxFRbYywsqGVv+SdKxTZCTr8w7XbVx3DGO/WYyTxgSEY5kwzmUpKHv7r47AEFuMCw4CsTzU+b7Whap4d7FPRLt6PRKZWznHRlJIFnDs4vf1DHVlPNtsqftsPzc2nLyWP0GYVKCR8YbnfCyd71MGvETfzHjqmy7famjk1ZiXhbzYOIbSP7Mk4Pc5Di0dVCk8zesNM/I3XKXXrgwFmAS2cZ2CwLe3YsDHG7C+KQQGTmarBPijE5yfIiNYqF/us2g01dMyn1cHPJMRFbOUbeqLYAjR3RoVV7Azs3zhLoExBnrG49qXNge4AHEtMY5RZ2Jgi4t07tsGvI59efIcehBzwija04i6dHRpYAW0V1HNyWwlI9iQBrU2LnuNhfoVQWn943XcA6qxQpcNTUasYzJ7NTIiLggynXQXgffSZK33hNBkeqgIJALTXGfO2ni2lF0evYIim0bjPm1S1uq+G+icGc5DJM8ccD40UIyzrDMuwPIo8qCVDHKMNKm0uzFwajhPJrBId2Ng7sZrA5k7QmzMEgNw1ZiclzM0QDeoqoHJUO7Uu/bPZlqswbw42Cg+DXJzh8aAKwn4pRsSgEYr18SoOtELA9433myf1Xr10ct3nkctwj21KxQpwOfmVFo2LvQ0XwJ37YLVbY6Ws/ulWYNZg3oV1my4VqhLKbRlreiTVJqeaQgt58lo/gMsdGwO2i5n0bVk6MQldaNIZoXlRDsPtAuV13bxiarUvpA2wD1y4vWzrpWryWbMkxHIyGzMkiUEPfY31QaFY8DXMW/mIq2BZH/SLpPJy3kUwX7u5TFnZJEEtoaFNSGXyAO6b6uPsdKFRPydZsmIlyqz9S7L4vcX1MlzISyPN4T1rT3HUouaWvz0EH3DhbrtrmG9GOghsIl1khKEwgGBzEZnq5NaTCW3eevaTXPj20znGYGuttGjIjHRoC6S/qsIs8eq1vddG9AjLHa/4xo1AmFSZlTmfhwNfVlinn30EOjJCEmdyf6BqTpG9AwF+KJ8QB+5SXnNLFKO5binZiF4Gkkq0hhxYWShn0LgZ4iMjXkDobHII3Qxg2QNN6yoncRAQOc5mbj80JzehfE8UsPGsnGrVZzZVJmQlI5ChT51Pot2/aVTBpwuBS4br92jl6cEiKBU1pmSQdle4t7xrAYkRsoIVDUqpz4/i/jmSi+QB2jNxm0wGmVNLo0r2o4zKZRRiUb7ydyesFEmMaAvh0VggNrWDHh5CxC1yUoEMrrSfNIlaeMZlGVrLJYENufJmRZ47+HEwas2E+lslNY3+kbj/VzXCehkdXteC3nJqE3fDWi2CAQsCkcXyimx6T67jeOfOZaNxymzdFYN2FNnynXy/VWk2VoVfg/WjHbmXQbYttkELA+covqTNJmcyySa1etI5CWuGo1g6WAQ2N4PfR8j8BbyZiLdGs8rQcgJuc3N1VWzzYVWN3pUMa9IjFmMYkkMN149JH1exb9BY/E+cq/sBmUfoHWfnE9ND5mkdEuh0Uz88qjoMzqwXQPMNbKUuSMjpmkzs39goFYH0my5LX9QS5hpqmgWx+wXpL3/DZ2ntJ1Hz2UfuUFGhpUSltTMjKeEO5fQc57UusxRtL8kMfNMCj23aFQTqWkc4JSaSMe5o6fPTmB/VqTtHXlCSETQ2+vzbucxK5HnZiUDxxwvTcZIs+sWpE/rX43DK4ds+qyiLLRamEeXDsxOgY68IftjUf9pHfiq7wSBjaUmk6gm0sJLwLzKM0BnVV5ds4euOwlpTwbIdm+2we7zjNdmF1hKyLkYfXDO7V2jR2Jc1E1kgzQW6OwmqU8+q0SoKbAsSDx24NiAfato3DryGhIdPefFN0tc3G/u+O1tcY0bywDpx+vyWj/TJ8RxeRjlQZvmEwQuj7LiNkZzfUGfU32Ocdvqazunee5Vtnv5UN5XiUe7O9KwAJPiny2JB8YYaK/zhwS7iWlqn0UhIcjrw4hj44lU4NeDsUzck2uz6bjJc3KhDtP04t+gy5JjDOpz7MgHoSungrZUUbfR8yRCPum4NnxpbLLA7I8JCLr0QA0wMKa9uLFkEOrvpcn42GXphbjkLoMg3RTrNu0X6cvhkRjLQo1L9XXgLCMzxLeq+xoLNOsZAJOnPDTrtM+ZpMiXwWu3lzUTSbG0HxhdaDTGUXN5xqjST45jpllnHoIcsyyEvvpa0AeJfYZ1Wk2otvW2DgZR6HP2DatVu/Ga1mOECMNkZinTP8fRY54s6ZKqa66HUe930RQzNDrOxjxOe9lzDFLAGNCb+wuxLb4MqkC3HhtXbUy+IwUbS7lOh8D0CwVwSWIcOTGs10MbeLUqiAX4cdD6vWM05LF3qTG7teOrJh86J59oNB1HA9IG0hkkK8ij50JHId8QN6B3HWthlHQIxpAAHHd5TweqBLWNi+xeQTEwaeOlXjk9GFb68iQsL7bkGXZuV7ftyHkYTDWAbcANQu2SL08y8MDGVff1UG4Nr85RtgU+ZyDDWDLD12RbIzHZuMzMbtLEwqFIiIzHs+vcb9+KXGCR3qRDReB0NdEEgfyh5J4rQx/DDPk2VcA9BHJMWx7dOPX8+h7WSy8DZKaphLzUuRjpYOPdlRt9SWJ4ffodtyp/NhUmjYkLF+22uEdSo+lIzI1n91nkyTZLwy0BEJfqsVAryC2yALTqafcYKyvKX2CkKbQ513uzEQJp4FoWxCIwaQRW5DWxfp5FMjD52Ddge1bDVYnA4r1VoZmEtLyvm4mIug+35r4cZhgNAqWMDxi/CKZGM5gb7Ay6UGbZmeAQkkOssW6GwJuy4TUL9QQ5AFXXqQZPkJPHSVigo84mrFnMs/GuEguf+XZa5AAmGe0wSWlugS0hDBjRq740mugo5NnUmectyotbn3eMga1qDBgReGoykc4yVXQeBXmSHuP4JQhsQj7XtFnuSKQyCZneavElGrS5iCRDKepObnB9dATyAkuvWMmkwVoKzBPxKlHAhg9EVohAtSR66I/ezIPXrIFhMzENgea17HeXKVdk8a0+WIAfRrwzI6U1DKqcw5IU+eBXLZpB9RaUMIlpbtI5r5ERw6ITOZ6vcyGior4IQf81BMp1TGLfNCZaF2plA6fHhrymzo5kYZ7Hs0/MCuOUduwdcTKtdBzNrWa+KxK1DELhrHmIYcMwgmwMZHFtWz2mERXn9h5DEkBKI+R65PqYDLUJWUuQXhixbxguddVIIzboEYp0llQZgJZ1EcPtW3ktswpAOZcQFY6BXMSrZIsMhpMhufpgXPXF5Xvi1nhOjwbclRFsOD6nXSlkEWgXngzxbsJsZ+7TcZdeW0fSQhkX40JbRZm0qu3anZFY00mT2k+u5zzrzITID3vhVtvN3Cd/421CmI3HBpX+cpdA74viZWIUkqCNBUCJ86E0kBD4KtbdNJz0WztaqtFadbRlhbmjTdrxLORFiIq4SzaKzDjkbsDMuU+PZapvtiEZwvZsfyEu7a5HD+1CefUPALXWrp2fGGYjPGv/MpABVQl82aLR1bbZ7TX+vZQQkzbICDaQioPkQrPco0ynydwZhaEgt0uGFu/YeLNMCuAzxOE5aSqFSGJ/Fj2AdnluSQWzy34edassb6bAQyBfc4DeNjWas93pqxHYUCIDXo0lxhS01ZbPHdg/gK3+7VtJj3FMez6R9727S35s5859oOqFDt9wGVBbmyLbZHZbZs8tAmUlbPvkdGMd+x6cJ63oC20KCKNRXKTxdjYkMeOrqaN2Tdeo1DPydTD77w5pFPIka0Okh8AhW0NMUyULbrTgoHC2jHnIcEQ9YMF+QeJ4nnYuHnAmG3QdHvFwEeiEhn7QxWd/7VK7AVXGxLBGAMgJef/QMXB/FgQ+n+XnRyUG2lQaxzxAx0hGXkrj7aYsbZd41o6PfYEIkZOGwFZQaxDXWKhx3w5jDIwYl/JbsoJuuABtxIa82bk+1zoL5bV7PC0kBuZCXGnn0ef7ZLaB16cDRSqw6wRG9KU0Tu3IB7OExaawrISgzL9GYC0sksazE1bMW+MxAj30sZtU7tOcc3iPi/NdNGbOayMcVcDn8yjIMnnNnM4hBpaYJyz0o+tBjoEy685u02ZXLMqsbrPsUGVUgr5dR7v/po2BnpCfZGKCJJ/rwLa16TYuWxTG9rTv9ww7MdANJFrZQyRGUHI04d1+LErE/X5lwK3mRE1J/L7rEsE7jWPWUCHNJED6kvH4eQhNBgT7hagl7q4OHAbeuMfSifrWR2U4jOdo/YJ+j1c50Hbasd/KxbJZShvOvSLuaPtK5mXXLvSoP6m97914kiaTJvEP6EaUC2HXKR+Kp4G8WXXl+up2D4G8GoiXdklbaGZcD9OIGHuzAb5ee5w8V31svLsf816lE6sLrRqtlvfl7VninzJgBj7eRwRuz/Kb7M9nj4NswN2If/kQljzwL5awGwR03LMz6WKkVjC79JJ1W1DLQp5XxPJ1lSfj4M8QqJ5ODOW60Ct3LJteG1q70PZHMwiAJjbsHmUWQlDmrulzJEMIGn2zKR1b/ezOKlCc4z/vzg+z+cC+sZ/zygD0oK7DY5VTlJr3/MG2ZvkthX0rrnP7AJ7vfb4OQJuwfb4XREnbto5KRiAbzBrdFiGx61yW/gNPw28kkLtkORBiF+Vt9SvdGLXN59GvngAIlF0Zm4dAxziuS3ViI5+T+zrnvIM6bmtfWWRqV3jgueydtWFNYmfReB4COd8pyLt7Z1v1gQmRJpHcXZzEvFVvawPmiXVnwNzYCFwaj7e9Mt70o38ejSu2j/JsexbWuX0UVMkiS6AL/I+aMpO2b8gfHwWV29Z14MyFysBw6kxQIuiT6i4W53Ks9B9+1etRbtm4dAR2IS8FtQ+arwvj/J4eyjGWeX099zhjqq6RJ1+UT7RVyvnazeVOQuJBMiKdw2xEkwy2wtoT6i+nhLob1Xd1CKNksDPrdhFl28ZpNIPAKwo/kA5cIOgCiW7/r20r9q3kNbeaCpMYyPFMYuDHe0lMS9v3Evv2vUoJZ3ZdPoAYkWMePQ8s3uXuDR4CrQCPoSeqhXkKw4zduPpGcdC5UXutTFQ8dzj0h97nkpiL8+DH3CcArFkVGLGuOzWJOc9iPJlZAGrmZe8I5HynNBk4VTxFH65JhomWs+sQJM/Jg0HHBT7eTsa67stDIPRAe+TEPve2TY1nD/lxlK44qpGkqmzfSmJahHwimSEG5KS0GJBn2vni5MI9BsZ/vJKHDWnlBOc6pdW1B+2u7qaGpde2GATafGUfUcDGr1eGu0p02203CM3dRiSm5jKflcSks9esAMVYQlikEXnJ2458OusXHqhzadSYvMRaNCvIErrPREQx0Ooy2RgiG9gFtzUIHAeNDhzK6s0geyxypts8osL7+PEL29pIicwqHDUtpmJg7tVkqqSiu858TtYyJCceynPLRAVZkV7bXKhDYhryWv7TFibNGN9njTExzNU5Z8b7ImOueL4X9/d8L8Z4/478bklM/bMIPI4SF8+EfJzwFl6GhUgIoU4EeRDkyXyd/BzbQiTGIkkWmkiTvrKMq939gV2vg8CB9red/Zrbo9P3DokZXn8NeZG2qspoLzUGdGngpdLOgr58OsabXZuKfWIYes7TPx4LtbMUw1Iwk3z2DKCIiro4ffGfRdBPQtqsrXj/phLV+f0d+P4darWsTPi+vxek1ZaPE2kTHZnq9faBygByoh88ZPRJSmyh3w5qCJQ4aJZrASW2yW8MyQCJ7KiuNPBsvkIgG9CZ3+P2kkE6x10SnZ9jyLW5RCnAZUlgSEw+Tm3AMxUE5tzcZ47OpU5YaBCXahPOPP1ja168mxMo9AnarIv8BAu8NN6LYz4RF/+o+wSAFR/vxYWKSH9/L7Gu/fhGamWF6bkj751p5pSQd12YGxCRbdKFZ9pb1Zj52TVBXot/9FNrQCErQmKsDuT7jrFbZkMHaKNfVn9PYqDq8gKBfJ5Xx/2BVmREzsgi4EnI5+NEph+LytuJdHAMTF06hIAQyw/+BqsmWN9x7BvKIBYiJAtNukZ9HpnHY7c63GDHIHAgLI5R+HpfPb865sZ5vwJ9ALDmj4/OMM8T2Dbk51aISUVXzgBSRtoO5UKRcjFgDAhLLPcYWJx3YUTYrIug0ZZFtMlYjmPkWpUoN254cKfASGLuulHnWLcP9X15vq9rK97r3J/kNN/fcX7bins8U5cGOSN9GLGecyEpMSD84wFElP4LfdOapovVUOUx8P2i10f/HfVKXoKVEeVk2oXWgel5TnGf8kcDx4W09biXRryl+y763zrmj7W15TZrmkxQlk8jzivatAHrdpRC33D17TPZF79+hRFmXKXHJltME6TRo7qUiaEuB3di7Dv9b53/a9qKb9/KsyoRzm9PnL9/1MrrRDEQyDstL+PrzEtBXshjemoxsoHRx8Sl/m4CHv/orlXWnAOEJLMoRYgNz7CzDhy0YTsQU3fH7zfv8EPHfVXsk7aKVBCJkHciL1WcS4I6p+RmW8Z7lTnfdO+mAzL4ak16oCS2QdvMEIolWiR+QUzypMgfPecXtTX9/r3Et/cd6Thx/v6B83spj09kmJwzTpNtCTGUtKUxGH/LgsS+ZQEe9YeeHvRrJU3ECxrlt4Tobu7lpP181ojN2Ga+seyk4w0jfTXgd5jlzfbVyJO25u0oiRaJfUdCOtJgsJIONQbMAJaAJRWdGGIYL1QIBiWa1Woi9ateznp0Fr0s0tWFeAi8en6jfXbA/wT0AcB6/PZREbgh7wnH+4aPj+PWAqIYM3IOWGLA2mIUDZTkN4lxKvbJ6JPfz7M3RAUwIEeVZ4SOQJYMXjWZh6hbA/9ZNspdfzILTe9blQgFgdt2Yj8KouzNAe0XP+aARwgdmUFW8hgGJ/N+XPputd+y9Dm9uKLdGMdS/WFmXR6r8dg9vopdnyUqnzTGzzYeAKzn92LAfTtxHgnPLWHfTpercKyTa0spt76hoi+QDtQJ7BWqhpOM2GfTV+1uPWMNS8JY87HxzBfpdrGRs+8vhDpu68e3UlKx7QnnkbHtJ47DmVkHkJaoPscDEXkpMw7NdZILDXJDnXVFeFDes+VAKecpwl3N58URRWwk0C47efuiiEgf/DXtVxpO2rrtqUy27wnHmXAcCfueJ5mjjEgoLOjLdV+oKbXQJ3HLjs4cvQImtwiJ3aeDQBvPvNdXj73jvVH6kwjKnbZ++7bXRExCSoV5ntUoiirUD7Gu7EYjUsqF7FQGGpaoDciCnef8RLjLT5AKiVlWqN8S8hDIMwzyZBDuLxjopyTErMufb9h124q7PI5qQACppsUyf6lzxpqBdOZ24Yqlsvu0JKbJBfMXu3yQbe3GcF7ZXzvWfArbr23DePyd9jcxHgCsvz/LrPuRs6k/ykXnAQgIhUweCVgjUG+CF5fOVEMsrjIstcqsvcNqZtu1fAhcgdZyoh4Cy5UostIv1mGdFy62neuvSUw+09Y9Fxd4ohiwhYsMLHUQxJhZ7hdTmxL2grxoBqZNspJ4V6XvEX0xiiEhUwJywS5n00b/oW39rRYpnbngagEQQ0BEnxWSHPWRgcjpNSKrBXmxC/X2DoQ8QVqNia3vIlJCDGqFOcZ45pIYs+9HScvfqK3PahAhLmsIxYgoBpWPvCAgIyOl7k76vT1RSIxkXlineaxT/a2j8RoCMaLQE+iutPg6FP5V3ScArP9X5/dEDvxziXiDcUqhVhWiIBQ5K4YKoMU/tYYdoFQa6cDZenaRD1GEuZYj/dFxod5+Gz/VBf99iMpVW//XFCUlAP+9RGWgiIAFRfPl+qEKWy37g+i/dRkNKMZjsqKKlgh9wky9otuZJPgJqPs7GE7a+tuZ+y2lAbyljLeQ8RYDmmnrgszcn6oWA8rEbQiDAfWysT4HqG6mOhAYwGeJk9j2SvNdJK7/Tsby2vo/FYFrKEgrzwOOnPHPKsgTinHPDOSQwQKxgKVmX3imob0Dz7gXJAYqndc/QRqIvHiuEuP22bayYzxeHfb3Nh4AxIzyL2UgVX2XckZCj4s2r52dH0gOVj4AoxtU7+xs/wp3+B9glM+0/weXQ8gRvvI3MgAAAABJRU5ErkJggg==\" id=\"image4b1a548f6c\" transform=\"scale(1 -1)translate(0 -112)\" x=\"40.603125\" y=\"-9.483219\" width=\"112\" height=\"112\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"mb71eb4b35f\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mb71eb4b35f\" x=\"41.719125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(38.537875 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#mb71eb4b35f\" x=\"86.359125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 20 -->\n","      <g transform=\"translate(79.996625 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_3\">\n","      <g>\n","       <use xlink:href=\"#mb71eb4b35f\" x=\"130.999125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 40 -->\n","      <g transform=\"translate(124.636625 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_4\">\n","     <!-- Sorted training inputs -->\n","     <g transform=\"translate(41.889844 149.759781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \n","L 3425 3897 \n","Q 3066 4069 2747 4153 \n","Q 2428 4238 2131 4238 \n","Q 1616 4238 1336 4038 \n","Q 1056 3838 1056 3469 \n","Q 1056 3159 1242 3001 \n","Q 1428 2844 1947 2747 \n","L 2328 2669 \n","Q 3034 2534 3370 2195 \n","Q 3706 1856 3706 1288 \n","Q 3706 609 3251 259 \n","Q 2797 -91 1919 -91 \n","Q 1588 -91 1214 -16 \n","Q 841 59 441 206 \n","L 441 856 \n","Q 825 641 1194 531 \n","Q 1563 422 1919 422 \n","Q 2459 422 2753 634 \n","Q 3047 847 3047 1241 \n","Q 3047 1584 2836 1778 \n","Q 2625 1972 2144 2069 \n","L 1759 2144 \n","Q 1053 2284 737 2584 \n","Q 422 2884 422 3419 \n","Q 422 4038 858 4394 \n","Q 1294 4750 2059 4750 \n","Q 2388 4750 2728 4690 \n","Q 3069 4631 3425 4513 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n","Q 1497 1759 1228 1600 \n","Q 959 1441 959 1056 \n","Q 959 750 1161 570 \n","Q 1363 391 1709 391 \n","Q 2188 391 2477 730 \n","Q 2766 1069 2766 1631 \n","L 2766 1759 \n","L 2194 1759 \n","z\n","M 3341 1997 \n","L 3341 0 \n","L 2766 0 \n","L 2766 531 \n","Q 2569 213 2275 61 \n","Q 1981 -91 1556 -91 \n","Q 1019 -91 701 211 \n","Q 384 513 384 1019 \n","Q 384 1609 779 1909 \n","Q 1175 2209 1959 2209 \n","L 2766 2209 \n","L 2766 2266 \n","Q 2766 2663 2505 2880 \n","Q 2244 3097 1772 3097 \n","Q 1472 3097 1187 3025 \n","Q 903 2953 641 2809 \n","L 641 3341 \n","Q 956 3463 1253 3523 \n","Q 1550 3584 1831 3584 \n","Q 2591 3584 2966 3190 \n","Q 3341 2797 3341 1997 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \n","Q 2906 2416 2648 2759 \n","Q 2391 3103 1925 3103 \n","Q 1463 3103 1205 2759 \n","Q 947 2416 947 1791 \n","Q 947 1169 1205 825 \n","Q 1463 481 1925 481 \n","Q 2391 481 2648 825 \n","Q 2906 1169 2906 1791 \n","z\n","M 3481 434 \n","Q 3481 -459 3084 -895 \n","Q 2688 -1331 1869 -1331 \n","Q 1566 -1331 1297 -1286 \n","Q 1028 -1241 775 -1147 \n","L 775 -588 \n","Q 1028 -725 1275 -790 \n","Q 1522 -856 1778 -856 \n","Q 2344 -856 2625 -561 \n","Q 2906 -266 2906 331 \n","L 2906 616 \n","Q 2728 306 2450 153 \n","Q 2172 0 1784 0 \n","Q 1141 0 747 490 \n","Q 353 981 353 1791 \n","Q 353 2603 747 3093 \n","Q 1141 3584 1784 3584 \n","Q 2172 3584 2450 3431 \n","Q 2728 3278 2906 2969 \n","L 2906 3500 \n","L 3481 3500 \n","L 3481 434 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-53\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"400.976562\"/>\n","      <use xlink:href=\"#DejaVuSans-61\" x=\"442.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"503.369141\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"531.152344\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"594.53125\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"622.314453\"/>\n","      <use xlink:href=\"#DejaVuSans-67\" x=\"685.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"749.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"780.957031\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"808.740234\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"872.119141\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"935.595703\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"998.974609\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"1038.183594\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_4\">\n","      <defs>\n","       <path id=\"m91a91d8f7e\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m91a91d8f7e\" x=\"40.603125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 0 -->\n","      <g transform=\"translate(27.240625 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m91a91d8f7e\" x=\"40.603125\" y=\"33.319219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 10 -->\n","      <g transform=\"translate(20.878125 37.118437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m91a91d8f7e\" x=\"40.603125\" y=\"55.639219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 20 -->\n","      <g transform=\"translate(20.878125 59.438437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m91a91d8f7e\" x=\"40.603125\" y=\"77.959219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 30 -->\n","      <g transform=\"translate(20.878125 81.758437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m91a91d8f7e\" x=\"40.603125\" y=\"100.279219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 40 -->\n","      <g transform=\"translate(20.878125 104.078437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Sorted testing inputs -->\n","     <g transform=\"translate(14.798438 118.160562)rotate(-90)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-53\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"400.976562\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"462.5\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"514.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"553.808594\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"581.591797\"/>\n","      <use xlink:href=\"#DejaVuSans-67\" x=\"644.970703\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"708.447266\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"740.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"768.017578\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"831.396484\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"894.873047\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"958.251953\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"997.460938\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 40.603125 121.483219 \n","L 40.603125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 152.203125 121.483219 \n","L 152.203125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 40.603125 121.483219 \n","L 152.203125 121.483219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 40.603125 9.883219 \n","L 152.203125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 159.178125 106.453219 \n","L 163.255125 106.453219 \n","L 163.255125 24.913219 \n","L 159.178125 24.913219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#p078ec34ecd)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABRCAYAAAD1sgc6AAAAnklEQVR4nJ2Suw7CQAwEjZT//1QqCnR+0XKzJxmSLqPx7krJo1/Ptq/nsgzbQRVBDqBH4wCkhTtkWDhqR8OSIHjii6H/Z2jtaLD2EDpm3DCkNvldftgB0GJIqM/TBfAfE+AAJcaSpZJRg1Fs0QyCjN5BRA0gkycEmTyRFhox7simsb/blSbGDWCDcdgB4MxwGu8CWAJ4shgqJ9IiBms/jwXJt9gA8G4AAAAASUVORK5CYII=\" id=\"image4ff9d396c3\" transform=\"scale(1 -1)translate(0 -81)\" x=\"159\" y=\"-25\" width=\"4\" height=\"81\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_9\">\n","      <defs>\n","       <path id=\"m5d6b4c57d7\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m5d6b4c57d7\" x=\"163.255125\" y=\"68.071954\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0.05 -->\n","      <g transform=\"translate(170.255125 71.871173)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m5d6b4c57d7\" x=\"163.255125\" y=\"29.690365\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0.10 -->\n","      <g transform=\"translate(170.255125 33.489583)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 159.178125 106.453219 \n","L 161.216625 106.453219 \n","L 163.255125 106.453219 \n","L 163.255125 24.913219 \n","L 161.216625 24.913219 \n","L 159.178125 24.913219 \n","L 159.178125 106.453219 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"pa2aa0c36fb\">\n","   <rect x=\"40.603125\" y=\"9.883219\" width=\"111.6\" height=\"111.6\"/>\n","  </clipPath>\n","  <clipPath id=\"p078ec34ecd\">\n","   <rect x=\"159.178125\" y=\"24.913219\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(attention_weights.unsqueeze(0).unsqueeze(0),\n","                  xlabel='Sorted training inputs',\n","                  ylabel='Sorted testing inputs')"],"id":"d7bf28ed"},{"cell_type":"markdown","metadata":{"origin_pos":25,"id":"84703545"},"source":["## [**带参数注意力汇聚**]\n","\n","非参数的Nadaraya-Watson核回归具有*一致性*（consistency）的优点：\n","如果有足够的数据，此模型会收敛到最优结果。\n","尽管如此，我们还是可以轻松地将可学习的参数集成到注意力汇聚中。\n","\n","例如，与 :eqref:`eq_nadaraya-watson-gaussian`略有不同，\n","在下面的查询$x$和键$x_i$之间的距离乘以可学习参数$w$：\n","\n","$$\\begin{aligned}f(x) &= \\sum_{i=1}^n \\alpha(x, x_i) y_i \\\\&= \\sum_{i=1}^n \\frac{\\exp\\left(-\\frac{1}{2}((x - x_i)w)^2\\right)}{\\sum_{j=1}^n \\exp\\left(-\\frac{1}{2}((x - x_j)w)^2\\right)} y_i \\\\&= \\sum_{i=1}^n \\mathrm{softmax}\\left(-\\frac{1}{2}((x - x_i)w)^2\\right) y_i.\\end{aligned}$$\n",":eqlabel:`eq_nadaraya-watson-gaussian-para`\n","\n","在本节的余下部分，我们将通过训练这个模型\n"," :eqref:`eq_nadaraya-watson-gaussian-para`来学习注意力汇聚的参数。\n","\n","### 批量矩阵乘法\n","\n",":label:`subsec_batch_dot`\n","\n","为了更有效地计算小批量数据的注意力，\n","我们可以利用深度学习开发框架中提供的批量矩阵乘法。\n","\n","假设第一个小批量数据包含$n$个矩阵$\\mathbf{X}_1,\\ldots, \\mathbf{X}_n$，\n","形状为$a\\times b$，\n","第二个小批量包含$n$个矩阵$\\mathbf{Y}_1, \\ldots, \\mathbf{Y}_n$，\n","形状为$b\\times c$。\n","它们的批量矩阵乘法得到$n$个矩阵\n","$\\mathbf{X}_1\\mathbf{Y}_1, \\ldots, \\mathbf{X}_n\\mathbf{Y}_n$，\n","形状为$a\\times c$。\n","因此，[**假定两个张量的形状分别是$(n,a,b)$和$(n,b,c)$，\n","它们的批量矩阵乘法输出的形状为$(n,a,c)$**]。\n"],"id":"84703545"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.286324Z","iopub.status.busy":"2022-07-31T02:26:27.285809Z","iopub.status.idle":"2022-07-31T02:26:27.291857Z","shell.execute_reply":"2022-07-31T02:26:27.291115Z"},"origin_pos":27,"tab":["pytorch"],"id":"f0220883","outputId":"658ec1f6-07bf-4376-d156-5025709a1c19"},"outputs":[{"data":{"text/plain":["torch.Size([2, 1, 6])"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["X = torch.ones((2, 1, 4))\n","Y = torch.ones((2, 4, 6))\n","torch.bmm(X, Y).shape"],"id":"f0220883"},{"cell_type":"markdown","metadata":{"origin_pos":29,"id":"ad3405be"},"source":["在注意力机制的背景中，我们可以[**使用小批量矩阵乘法来计算小批量数据中的加权平均值**]。\n"],"id":"ad3405be"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.295896Z","iopub.status.busy":"2022-07-31T02:26:27.295689Z","iopub.status.idle":"2022-07-31T02:26:27.301935Z","shell.execute_reply":"2022-07-31T02:26:27.301284Z"},"origin_pos":31,"tab":["pytorch"],"id":"48883a71","outputId":"1f199d1f-3c30-4470-92e6-76490af15623"},"outputs":[{"data":{"text/plain":["tensor([[[ 4.5000]],\n","\n","        [[14.5000]]])"]},"execution_count":9,"metadata":{},"output_type":"execute_result"}],"source":["weights = torch.ones((2, 10)) * 0.1\n","values = torch.arange(20.0).reshape((2, 10))\n","torch.bmm(weights.unsqueeze(1), values.unsqueeze(-1))"],"id":"48883a71"},{"cell_type":"markdown","metadata":{"origin_pos":33,"id":"c969e67a"},"source":["### 定义模型\n","\n","基于 :eqref:`eq_nadaraya-watson-gaussian-para`中的\n","[**带参数的注意力汇聚**]，使用小批量矩阵乘法，\n","定义Nadaraya-Watson核回归的带参数版本为：\n"],"id":"c969e67a"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.306089Z","iopub.status.busy":"2022-07-31T02:26:27.305630Z","iopub.status.idle":"2022-07-31T02:26:27.311475Z","shell.execute_reply":"2022-07-31T02:26:27.310786Z"},"origin_pos":35,"tab":["pytorch"],"id":"77fd65b0"},"outputs":[],"source":["class NWKernelRegression(nn.Module):\n","    def __init__(self, **kwargs):\n","        super().__init__(**kwargs)\n","        self.w = nn.Parameter(torch.rand((1,), requires_grad=True))\n","\n","    def forward(self, queries, keys, values):\n","        # queries和attention_weights的形状为(查询个数，“键－值”对个数)\n","        queries = queries.repeat_interleave(keys.shape[1]).reshape((-1, keys.shape[1]))\n","        self.attention_weights = nn.functional.softmax(\n","            -((queries - keys) * self.w)**2 / 2, dim=1)\n","        # values的形状为(查询个数，“键－值”对个数)\n","        return torch.bmm(self.attention_weights.unsqueeze(1),\n","                         values.unsqueeze(-1)).reshape(-1)"],"id":"77fd65b0"},{"cell_type":"markdown","metadata":{"origin_pos":37,"id":"eebd30cc"},"source":["### 训练\n","\n","接下来，[**将训练数据集变换为键和值**]用于训练注意力模型。\n","在带参数的注意力汇聚模型中，\n","任何一个训练样本的输入都会和除自己以外的所有训练样本的“键－值”对进行计算，\n","从而得到其对应的预测输出。\n"],"id":"eebd30cc"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.315630Z","iopub.status.busy":"2022-07-31T02:26:27.315179Z","iopub.status.idle":"2022-07-31T02:26:27.320562Z","shell.execute_reply":"2022-07-31T02:26:27.319876Z"},"origin_pos":39,"tab":["pytorch"],"id":"2039d2e6"},"outputs":[],"source":["# X_tile的形状:(n_train，n_train)，每一行都包含着相同的训练输入\n","X_tile = x_train.repeat((n_train, 1))\n","# Y_tile的形状:(n_train，n_train)，每一行都包含着相同的训练输出\n","Y_tile = y_train.repeat((n_train, 1))\n","# keys的形状:('n_train'，'n_train'-1)\n","keys = X_tile[(1 - torch.eye(n_train)).type(torch.bool)].reshape((n_train, -1))\n","# values的形状:('n_train'，'n_train'-1)\n","values = Y_tile[(1 - torch.eye(n_train)).type(torch.bool)].reshape((n_train, -1))"],"id":"2039d2e6"},{"cell_type":"markdown","metadata":{"origin_pos":41,"id":"dfce7284"},"source":["[**训练带参数的注意力汇聚模型**]时，使用平方损失函数和随机梯度下降。\n"],"id":"dfce7284"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:27.324700Z","iopub.status.busy":"2022-07-31T02:26:27.324248Z","iopub.status.idle":"2022-07-31T02:26:28.075798Z","shell.execute_reply":"2022-07-31T02:26:28.075021Z"},"origin_pos":43,"tab":["pytorch"],"id":"d2e6ad27","outputId":"22a48dc7-4ad2-4e27-81a6-28be632dcc8d"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"246.284375pt\" height=\"180.65625pt\" viewBox=\"0 0 246.284375 180.65625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:28.039709</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 180.65625 \n","L 246.284375 180.65625 \n","L 246.284375 0 \n","L 0 0 \n","L 0 180.65625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 40.603125 143.1 \n","L 235.903125 143.1 \n","L 235.903125 7.2 \n","L 40.603125 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 40.603125 143.1 \n","L 40.603125 7.2 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"m86fea0b811\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m86fea0b811\" x=\"40.603125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 1 -->\n","      <g transform=\"translate(37.421875 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 89.428125 143.1 \n","L 89.428125 7.2 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m86fea0b811\" x=\"89.428125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 2 -->\n","      <g transform=\"translate(86.246875 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 138.253125 143.1 \n","L 138.253125 7.2 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m86fea0b811\" x=\"138.253125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 3 -->\n","      <g transform=\"translate(135.071875 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 187.078125 143.1 \n","L 187.078125 7.2 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m86fea0b811\" x=\"187.078125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 4 -->\n","      <g transform=\"translate(183.896875 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 235.903125 143.1 \n","L 235.903125 7.2 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m86fea0b811\" x=\"235.903125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 5 -->\n","      <g transform=\"translate(232.721875 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_6\">\n","     <!-- epoch -->\n","     <g transform=\"translate(123.025 171.376563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n","L 3122 2828 \n","Q 2878 2963 2633 3030 \n","Q 2388 3097 2138 3097 \n","Q 1578 3097 1268 2742 \n","Q 959 2388 959 1747 \n","Q 959 1106 1268 751 \n","Q 1578 397 2138 397 \n","Q 2388 397 2633 464 \n","Q 2878 531 3122 666 \n","L 3122 134 \n","Q 2881 22 2623 -34 \n","Q 2366 -91 2075 -91 \n","Q 1284 -91 818 406 \n","Q 353 903 353 1747 \n","Q 353 2603 823 3093 \n","Q 1294 3584 2113 3584 \n","Q 2378 3584 2631 3529 \n","Q 2884 3475 3122 3366 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-65\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n","      <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 40.603125 133.318716 \n","L 235.903125 133.318716 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <defs>\n","       <path id=\"mae716d5dd3\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"133.318716\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 20 -->\n","      <g transform=\"translate(20.878125 137.117935)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 40.603125 108.997871 \n","L 235.903125 108.997871 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"108.997871\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 25 -->\n","      <g transform=\"translate(20.878125 112.79709)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 40.603125 84.677026 \n","L 235.903125 84.677026 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"84.677026\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 30 -->\n","      <g transform=\"translate(20.878125 88.476245)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 40.603125 60.356182 \n","L 235.903125 60.356182 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"60.356182\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 35 -->\n","      <g transform=\"translate(20.878125 64.1554)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_19\">\n","      <path d=\"M 40.603125 36.035337 \n","L 235.903125 36.035337 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"36.035337\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 40 -->\n","      <g transform=\"translate(20.878125 39.834556)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_21\">\n","      <path d=\"M 40.603125 11.714492 \n","L 235.903125 11.714492 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#mae716d5dd3\" x=\"40.603125\" y=\"11.714492\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 45 -->\n","      <g transform=\"translate(20.878125 15.513711)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_13\">\n","     <!-- loss -->\n","     <g transform=\"translate(14.798437 84.807812)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n","L 1178 4863 \n","L 1178 0 \n","L 603 0 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-6c\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"27.783203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"88.964844\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"141.064453\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_23\">\n","    <path d=\"M 40.603125 13.377273 \n","L 89.428125 133.838404 \n","L 138.253125 134.723586 \n","L 187.078125 135.739528 \n","L 235.903125 136.922727 \n","\" clip-path=\"url(#p2cfca49d4d)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 40.603125 143.1 \n","L 40.603125 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 235.903125 143.1 \n","L 235.903125 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 40.603125 143.1 \n","L 235.903125 143.1 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 40.603125 7.2 \n","L 235.903125 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p2cfca49d4d\">\n","   <rect x=\"40.603125\" y=\"7.2\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["net = NWKernelRegression()\n","loss = nn.MSELoss(reduction='none')\n","trainer = torch.optim.SGD(net.parameters(), lr=0.5)\n","animator = d2l.Animator(xlabel='epoch', ylabel='loss', xlim=[1, 5])\n","\n","for epoch in range(5):\n","    trainer.zero_grad()\n","    l = loss(net(x_train, keys, values), y_train)\n","    l.sum().backward()\n","    trainer.step()\n","    print(f'epoch {epoch + 1}, loss {float(l.sum()):.6f}')\n","    animator.add(epoch + 1, float(l.sum()))"],"id":"d2e6ad27"},{"cell_type":"markdown","metadata":{"origin_pos":45,"id":"31002230"},"source":["如下所示，训练完带参数的注意力汇聚模型后，我们发现：\n","在尝试拟合带噪声的训练数据时，\n","[**预测结果绘制**]的线不如之前非参数模型的平滑。\n"],"id":"31002230"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:28.079025Z","iopub.status.busy":"2022-07-31T02:26:28.078542Z","iopub.status.idle":"2022-07-31T02:26:28.252961Z","shell.execute_reply":"2022-07-31T02:26:28.252218Z"},"origin_pos":47,"tab":["pytorch"],"id":"914939bb","outputId":"cda2cb94-eaf8-4c13-87b4-cc2dca1ec856"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"248.301563pt\" height=\"184.455469pt\" viewBox=\"0 0 248.301563 184.455469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:28.204545</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 184.455469 \n","L 248.301563 184.455469 \n","L 248.301563 -0 \n","L 0 -0 \n","L 0 184.455469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","L 237.920313 10.999219 \n","L 42.620312 10.999219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"m6d3cdae01a\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(39.439062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 81.680312 146.899219 \n","L 81.680312 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"81.680312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 1 -->\n","      <g transform=\"translate(78.499062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 120.740313 146.899219 \n","L 120.740313 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"120.740313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 2 -->\n","      <g transform=\"translate(117.559062 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 159.800313 146.899219 \n","L 159.800313 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"159.800313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 3 -->\n","      <g transform=\"translate(156.619063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 198.860313 146.899219 \n","L 198.860313 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"198.860313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 4 -->\n","      <g transform=\"translate(195.679063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m6d3cdae01a\" x=\"237.920313\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 5 -->\n","      <g transform=\"translate(234.739063 161.497656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_7\">\n","     <!-- x -->\n","     <g transform=\"translate(137.310937 175.175781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n","L 2247 1797 \n","L 3578 0 \n","L 2900 0 \n","L 1881 1375 \n","L 863 0 \n","L 184 0 \n","L 1544 1831 \n","L 300 3500 \n","L 978 3500 \n","L 1906 2253 \n","L 2834 3500 \n","L 3513 3500 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-78\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <defs>\n","       <path id=\"maea430a094\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"146.899219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- −1 -->\n","      <g transform=\"translate(20.878125 150.698437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n","L 4684 2272 \n","L 4684 1741 \n","L 678 1741 \n","L 678 2272 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 42.620312 124.249219 \n","L 237.920313 124.249219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"124.249219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0 -->\n","      <g transform=\"translate(29.257812 128.048437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 42.620312 101.599219 \n","L 237.920313 101.599219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"101.599219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 1 -->\n","      <g transform=\"translate(29.257812 105.398437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_19\">\n","      <path d=\"M 42.620312 78.949219 \n","L 237.920313 78.949219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"78.949219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 2 -->\n","      <g transform=\"translate(29.257812 82.748437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_21\">\n","      <path d=\"M 42.620312 56.299219 \n","L 237.920313 56.299219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"56.299219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 3 -->\n","      <g transform=\"translate(29.257812 60.098437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_23\">\n","      <path d=\"M 42.620312 33.649219 \n","L 237.920313 33.649219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"33.649219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 4 -->\n","      <g transform=\"translate(29.257812 37.448437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_25\">\n","      <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#maea430a094\" x=\"42.620312\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 5 -->\n","      <g transform=\"translate(29.257812 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_15\">\n","     <!-- y -->\n","     <g transform=\"translate(14.798437 81.908594)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-79\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_27\">\n","    <path d=\"M 42.620312 124.249219 \n","L 46.526313 116.136982 \n","L 50.432313 108.999323 \n","L 54.338313 102.217148 \n","L 58.244313 95.726379 \n","L 62.150312 89.522233 \n","L 66.056313 83.619087 \n","L 69.962312 78.038824 \n","L 73.868313 72.806 \n","L 77.774314 67.945395 \n","L 81.680312 63.480584 \n","L 85.586313 59.432954 \n","L 89.492314 55.821098 \n","L 93.398311 52.660258 \n","L 97.304312 49.962036 \n","L 101.210313 47.734078 \n","L 105.116313 45.979911 \n","L 109.022314 44.69881 \n","L 112.928315 43.885737 \n","L 116.834312 43.531371 \n","L 120.740313 43.622105 \n","L 124.646309 44.140188 \n","L 128.552314 45.063873 \n","L 132.458311 46.367563 \n","L 136.364316 48.022135 \n","L 140.270312 49.995107 \n","L 144.176318 52.251038 \n","L 148.082314 54.751808 \n","L 151.98832 57.457039 \n","L 155.894316 60.324422 \n","L 159.800313 63.310193 \n","L 163.706318 66.369546 \n","L 167.612314 69.45704 \n","L 171.518311 72.527086 \n","L 175.424316 75.534393 \n","L 179.330312 78.434371 \n","L 183.236318 81.183652 \n","L 187.142314 83.740416 \n","L 191.048311 86.06491 \n","L 194.954316 88.119776 \n","L 198.860313 89.870412 \n","L 202.766309 91.285368 \n","L 206.672305 92.336626 \n","L 210.57832 92.999866 \n","L 214.484316 93.254719 \n","L 218.390312 93.084986 \n","L 222.296309 92.478756 \n","L 226.202305 91.428572 \n","L 230.10832 89.931453 \n","L 234.014316 87.988973 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"line2d_28\">\n","    <path d=\"M 42.620312 118.782693 \n","L 46.526313 114.777433 \n","L 50.432313 109.441735 \n","L 54.338313 101.596157 \n","L 58.244313 94.638118 \n","L 62.150312 89.90513 \n","L 66.056313 84.961829 \n","L 69.962312 79.865162 \n","L 73.868313 75.827984 \n","L 77.774314 72.907572 \n","L 81.680312 72.502429 \n","L 85.586313 71.766417 \n","L 89.492314 66.334375 \n","L 93.398311 60.466311 \n","L 97.304312 55.070154 \n","L 101.210313 48.84475 \n","L 105.116313 45.164748 \n","L 109.022314 45.336393 \n","L 112.928315 47.282915 \n","L 116.834312 48.262259 \n","L 120.740313 46.401238 \n","L 124.646309 45.76878 \n","L 128.552314 47.411914 \n","L 132.458311 48.662089 \n","L 136.364316 48.549786 \n","L 140.270312 48.02038 \n","L 144.176318 48.247592 \n","L 148.082314 50.266288 \n","L 151.98832 53.410711 \n","L 155.894316 56.68929 \n","L 159.800313 62.270755 \n","L 163.706318 69.390423 \n","L 167.612314 75.108886 \n","L 171.518311 78.394555 \n","L 175.424316 80.498018 \n","L 179.330312 82.064329 \n","L 183.236318 83.222727 \n","L 187.142314 84.778174 \n","L 191.048311 86.854411 \n","L 194.954316 88.498936 \n","L 198.860313 88.76577 \n","L 202.766309 85.592383 \n","L 206.672305 78.857437 \n","L 210.57832 78.131523 \n","L 214.484316 87.128333 \n","L 218.390312 95.513091 \n","L 222.296309 97.349185 \n","L 226.202305 96.382155 \n","L 230.10832 94.69543 \n","L 234.014316 92.295569 \n","\" clip-path=\"url(#p389eb8dce8)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"line2d_29\">\n","    <defs>\n","     <path id=\"mc81d49f451\" d=\"M 0 3 \n","C 0.795609 3 1.55874 2.683901 2.12132 2.12132 \n","C 2.683901 1.55874 3 0.795609 3 0 \n","C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \n","C 1.55874 -2.683901 0.795609 -3 0 -3 \n","C -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \n","C -2.683901 -1.55874 -3 -0.795609 -3 0 \n","C -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \n","C -1.55874 2.683901 -0.795609 3 0 3 \n","z\n","\" style=\"stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </defs>\n","    <g clip-path=\"url(#p389eb8dce8)\">\n","     <use xlink:href=\"#mc81d49f451\" x=\"44.707936\" y=\"125.985601\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"49.333159\" y=\"103.170939\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"60.036688\" y=\"105.931758\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"62.900252\" y=\"89.437088\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"63.599851\" y=\"79.591613\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"71.181077\" y=\"79.555681\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"71.282072\" y=\"77.053631\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"77.419072\" y=\"66.872935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"89.621611\" y=\"90.736426\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"93.643908\" y=\"56.317412\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"93.720667\" y=\"42.085824\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"106.709574\" y=\"46.449608\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"109.919949\" y=\"39.62002\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"115.89625\" y=\"56.959304\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"122.842639\" y=\"38.21161\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"128.205093\" y=\"50.21983\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"132.63648\" y=\"49.415921\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"139.87121\" y=\"44.880142\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"140.663156\" y=\"51.174561\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"141.536476\" y=\"55.449425\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"144.634723\" y=\"41.94644\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"144.830111\" y=\"38.233875\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"150.066007\" y=\"65.603482\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"152.379339\" y=\"51.619989\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"159.657298\" y=\"39.76906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"161.33007\" y=\"76.584841\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"166.84419\" y=\"78.888202\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"167.057738\" y=\"77.713809\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"174.818409\" y=\"72.789805\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"174.926379\" y=\"66.252119\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"175.244787\" y=\"85.023226\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"177.112919\" y=\"91.666709\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"178.537659\" y=\"90.531084\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"183.587898\" y=\"75.135897\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"184.210875\" y=\"80.267727\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"185.439528\" y=\"81.906104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"185.855635\" y=\"89.10104\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"189.699432\" y=\"87.132267\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"191.165836\" y=\"88.740108\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"193.231666\" y=\"91.45634\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"196.150943\" y=\"86.942672\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"198.969643\" y=\"92.356445\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"208.728422\" y=\"71.578922\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"219.230498\" y=\"97.103015\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"226.081464\" y=\"113.938906\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"227.570982\" y=\"76.711935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"231.923743\" y=\"100.46935\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"232.112565\" y=\"99.46274\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"236.255084\" y=\"91.129232\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","     <use xlink:href=\"#mc81d49f451\" x=\"237.390778\" y=\"76.54076\" style=\"fill: #ff7f0e; fill-opacity: 0.5; stroke: #ff7f0e; stroke-opacity: 0.5\"/>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 42.620312 146.899219 \n","L 42.620312 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 237.920313 146.899219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 42.620312 146.899219 \n","L 237.920313 146.899219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 42.620312 10.999219 \n","L 237.920313 10.999219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"legend_1\">\n","    <g id=\"patch_7\">\n","     <path d=\"M 173.58125 48.355469 \n","L 230.920313 48.355469 \n","Q 232.920313 48.355469 232.920313 46.355469 \n","L 232.920313 17.999219 \n","Q 232.920313 15.999219 230.920313 15.999219 \n","L 173.58125 15.999219 \n","Q 171.58125 15.999219 171.58125 17.999219 \n","L 171.58125 46.355469 \n","Q 171.58125 48.355469 173.58125 48.355469 \n","z\n","\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n","    </g>\n","    <g id=\"line2d_30\">\n","     <path d=\"M 175.58125 24.097656 \n","L 185.58125 24.097656 \n","L 195.58125 24.097656 \n","\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","    </g>\n","    <g id=\"text_16\">\n","     <!-- Truth -->\n","     <g transform=\"translate(203.58125 27.597656)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-54\" d=\"M -19 4666 \n","L 3928 4666 \n","L 3928 4134 \n","L 2272 4134 \n","L 2272 0 \n","L 1638 0 \n","L 1638 4134 \n","L -19 4134 \n","L -19 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-54\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"46.333984\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"87.447266\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"150.826172\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"190.035156\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_31\">\n","     <path d=\"M 175.58125 38.775781 \n","L 185.58125 38.775781 \n","L 195.58125 38.775781 \n","\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Pred -->\n","     <g transform=\"translate(203.58125 42.275781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \n","L 1259 2394 \n","L 2053 2394 \n","Q 2494 2394 2734 2622 \n","Q 2975 2850 2975 3272 \n","Q 2975 3691 2734 3919 \n","Q 2494 4147 2053 4147 \n","L 1259 4147 \n","z\n","M 628 4666 \n","L 2053 4666 \n","Q 2838 4666 3239 4311 \n","Q 3641 3956 3641 3272 \n","Q 3641 2581 3239 2228 \n","Q 2838 1875 2053 1875 \n","L 1259 1875 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-50\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"58.552734\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"97.416016\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"158.939453\"/>\n","     </g>\n","    </g>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p389eb8dce8\">\n","   <rect x=\"42.620312\" y=\"10.999219\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# keys的形状:(n_test，n_train)，每一行包含着相同的训练输入（例如，相同的键）\n","keys = x_train.repeat((n_test, 1))\n","# value的形状:(n_test，n_train)\n","values = y_train.repeat((n_test, 1))\n","y_hat = net(x_test, keys, values).unsqueeze(1).detach()\n","plot_kernel_reg(y_hat)"],"id":"914939bb"},{"cell_type":"markdown","metadata":{"origin_pos":49,"id":"cd16e2b6"},"source":["为什么新的模型更不平滑了呢？\n","我们看一下输出结果的绘制图：\n","与非参数的注意力汇聚模型相比，\n","带参数的模型加入可学习的参数后，\n","[**曲线在注意力权重较大的区域变得更不平滑**]。\n"],"id":"cd16e2b6"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:26:28.256470Z","iopub.status.busy":"2022-07-31T02:26:28.255973Z","iopub.status.idle":"2022-07-31T02:26:28.438268Z","shell.execute_reply":"2022-07-31T02:26:28.437542Z"},"origin_pos":51,"tab":["pytorch"],"id":"2ba62905","outputId":"779f911b-5de0-4a10-801e-33c310fd0f78"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"193.35825pt\" height=\"159.039469pt\" viewBox=\"0 0 193.35825 159.039469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:26:28.387933</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 159.039469 \n","L 193.35825 159.039469 \n","L 193.35825 0 \n","L 0 0 \n","L 0 159.039469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 40.603125 121.483219 \n","L 152.203125 121.483219 \n","L 152.203125 9.883219 \n","L 40.603125 9.883219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p59be1a30fe)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAYAAADG4PRLAAAQz0lEQVR4nO2d2W8cV3bGf7eqel/ZlEhqsWRbcsbOjMdOJrMgSDABMshLAuQPyD+YpwB5CII8BME8BPAkmTixnYFsrZa5r83eu7abh3NvVbUojymrSbbI+gCiqWLToPvDOfcs3zlX6WFXk+NCobWG6QgmQ4hD9HQMkyH6+VcwHoI2FCkFjgOuB6UyAN4F/t05MOQB6BjiKP2KopNvdhxwXHBdeXVUTuCFQ8cQxzAdofc30IEP4z5EIQS+vEcpeW22obGMKhShWALl5AReOGJjecEU3T+C0IfRIH0OYnkAxQqq2QGvgCqUQOUWeKHQWoM/Bn9CfLAFO9+I6wxD8Dxod6BQBCUEquYyqtYybtTLCVwI+BP0sAsHW7C1Ls9cFyo1WHsLKnUh0FHQ7EC5lp6F5AReGLTWEEfo4z30+kPY30FHEcp1xeqKJag2UbWGEKgccZuuZwgVq8wJvChoDVGIfvQZ+tP/EKvzPHSlgqrUoNFCdVZRlTqgJJAplsErmqBGAhvnQv8nrii01hAFEE7hYBe9sQmjEVQqqEoVqjWo1iXadAvgFcTyHNech4bQ/Ay8IMQRjHroYRf9n7/hd//8gPd/9R7ez/4Uak2wlldpQEESdkniXZQza3M5gRcBHaMnQ/TxPsHBgME0FJdaa0Ktgao2oVwV63Pc9PfUSYeZE3jOsGUz/et/RD95RLDXp9Mo4t6+gXr7A1SxAsWKOROLLxCoTvz3cgLPEVprsbQwQD9+yPSLx4Rjn2q1AK0WqtaW884zud9LXOaLyIOYc4DWGh3HUh7zx+jeAb1//ZTf/vtzip0at/7mJ6gf/hGUKlAoies0ifp3ISfwPKC1qXmGEPro7h7//fCQfzoc4HXqqL/4K9R7H4nr9CTXU66HOgWBuQs9IyTuEsn3CH2pdx7vw/4mReVwo+jirXZQq3dQlQY2PTgNcRY5gXNG2h6SSgs6lnrndITuH6GffAFPvqTqOrxdLqDevYe69R4USt953r0MOYFzRGJ1OjYEhqbT4KOHPXTvEPZ30aMRa6tVSkcOLK9I4PKSFOE0yAmcE7QpjSUuU8fgT+TMO9hCbzyGvR30F/8LYcja3/6ctWoV9aOfybn3Cm4zi5zAOWDW8jKd9TBABz56MpIe32gA06mcc2s3oHMNVWt9L9dpkRP4ipg549KnQpg/lkZsMBVtS/8IPexJq+joAO1PodGAeh0+/gVq5Q7Ul17r78kJPCW0fpn2S6dExrE0Y+MQHfriOkcDGPVgPAJ/Kj+vVKBWQ12/jWpdk7zvNZATeArobGCSFSHp2L5B0oTpEB1MYTQQEkc9mI7lfGu2UcqRElmzLfVOrzRbKvseyAk8LeKYxOKyKYLN9cIAPTwGf4oe90WQNBnCZCyk1RoiBWx2pGhdqkrq8D2DF4ucwO9AYn1RkCrIIA1UkvrmFKZjUZVF5rnVs3ielMeKJVRzWWQR7nw++pzAb8GJhDyYZpRippsehenPpyP0eABhkKrJCmUoKqg2RIxULEufzxVCX9f6ICfw5cGJdYtggpMwJcacfToM5LklNQyTpiteQX7XK4oEsFJH2f6e6526UH0aXGkCtXWH6RN5ieNMNSUyEeWxnGuWxDBE2+9j83vFsoiPiiY4KddQXkGClWI5JdeIlOaBK0ugtlb2UguM0/POlsPCUM5Bc75pK3+3kahyULaPVyiD68q/vYymxRKnnLm4T7jCBKJNwg0ZEs1rGKbERaG4y3FfSLPW5iiJLnGFjEIR1egY0W0hHUKxYiS3YIRI8+3gXV0C7dn1YkXFFqHNmadDX4rRLw6cKBOEKEeI8UqpBMItGIILqZLMvG9elmdxZQg8EaxEgeRp2YDFpAQ69KVyEodijYAqVeQ9lhDrFs0z5XrSUVfG8jABjZPKAOdNHlwhAoFZa4tC9HSUhvyQWth0LCRGJtfzPNGruG5ylqlEp6lS0rySEGat8gyJs7gSBCatnpnSVyClrqxbNARrG6xYYZFXFLW046ak2e9RIpLO/syec2dMHlwBApNWTxwaEo0V+mMZ53pxkFJrsTSlUlV0sQylmnnupARmiLJknwdpWVxaAmcmX7WWiDMMUisLprPFafuhW3LcAsrzhLxiOXWfiaw9HTDJSt3Pkzy4pAQm9UubkEehSNkH3STx1qEvP89+4MbCVLlmJH5FEdp6RcntrIuEmQET++y8yYNLSmBSQbGJeBSix0NprmYt05a8rCu0rZ1CUeqWXqb05bxgcTBD/kWQB5eVQJsixBEEE7Q/QW8+gqODNJDpXEfdvJ+ed5Cca6qQzensQgFvIQh7EZeOwMR9hr5Y3mgg4qLhAAb99I3NJShVZKDSWpTN2WwJzHGEOOdskvB54FIQOLuqI4bJiHj7qXTDB6YIPR5JX86QQbkqYlrHTfhLLTHTMTijCsq8cCkIBMy5Fyduk4NtWZLT70n0WSgKgXbevFiWMWYn8xEkAYozU0FZZLzxBCbTrqbtQxigewewuyWu0/eFjM51aLQSq1Kta8Y9vmR8K5OML6rlWbyRBM7UNW1VJQwkOZ8M0Pub6O0NCAKxumIR1WihVu+k7Zx6+1sV0YtOWhZvHIFJkCL/kC9/IuQNj0W+Puwl550ql6FcgVpLtj6YhBuviD383iTCXsTCE3jC2mxinnTPI/TRNvpgC4724GAX4ghVq8u5t7QM1TrO6h2otZOKCY73WoroRcHCEnhSAZ2JNKO0JCZR5xBGfZGuj0dCXL0pQUpzSebNbWpg8Zp6zEXBwhKYSvgyWkyb340HQDr1qreewfY6TMboyQTVbKPel4lXVWtJUbrSMG7T4s11m1ksJIHapgRZ4WxS14ykEG1LZaEv4tnJGB2GEnGWStBclopKsjBgNmB5k8+9LBaSwEQoa2V7SW0zQvtjOe+sIiyKhKBWB1Uy6q+VW6j6kmmyFtK+3iUhLYvFJBCdqsASooyQdtSTrzBMLdRxoVYX+XqtiWqvSDfBlsFQlyJgeRkWjsB0m8MI7U/k+ygSMgNfnoXhrBSiJWsZVcUQWGlkapiXkziLhSIw7eNFIlMf9mTWIDYEWnV0FKS/5LhSVWksoYpls+lB2kCX0WW+iIUh0K5fFKJ8GPVlyse6yqwEsDi7P4xyTciz41qXJEU4DRaCQJ1N0Ccj6eEd70O/O/tGu3KxsZQs/VaOK2WxSj3t2znzUz4vOhaCwIS80JeS2HRk+nlRWmB23WSnpipVEgKT9cPW8mwX4YrgQglMFGPBNBnP0s8fSG1zbDSbBdMZt1tsKw1oX0dlJXzFspGuL3bv7ixwsRaYHZ70J5IeHB9KA9ZKHRyxOgpFIzIqydCIPefs/ugrSB5cNIHhVEa3jnbQTz6H7iH62WNxkx/+BJodcZduIRUaFcvp4m8AVDI4ctXIgwskMFFLhwG6uw+b36CPj2BvTzY5FEuoxlKyJ1pZdZhXTPdGZzroV5E8uCACtZU+DLvE+5vw9QP008fiUisV2Z3ZXsl0zZ00QMncmZDgipIHF2WBNlk/2IJnD9BPHxE+/ga3UUbdvYNqtVFLK1BtzWpTMrL2q2pxL+LcCdRxLKKjwEfvfoN+/gR6PZxKAdWoo1bXZAFcoTSbFiQu82qedd+GcyVQW6X0eIAe9dAPPif45FPcegmn1YDVVXj/Y3Gd5VrmjgRBTtxJnFulV2fmFPSgiz7cgX6feOyjPFfOvVZbGrDV5swcgrqiEeZpcOYWmC1QJwn7F5+g15+h1zeIxj6qs4T6yS9geQ21ejeJNHPSvhtnb4FZwW0YSDvocA8ODoj9EKfoQbUKrWVztVpxRjGW4/fj7M/AKEiuWNO7z9EH2+j/+4Lp8z1K76zh/sE91B9+hHP3A7PZqHyqdfs5BOdggbFEnNMR+mgHDnYIdrv4O8dQLqNu34VVc82a7aJf8ibsPHH2FjgZoXeeobt78OAzdK+HUy5Qut1B3bsPP/gYZ+V22svLA5ZXwtkT6I/Rm09hbxv95AlMJriVIm6jCm+9i3P7vZlr1XLyXg1nH4WO+vD8Cbp7hO4PAFA31mT1cHtFitSmNJaT9+qYO4EvLtTRh1vEn39GNJgS9ce4jQqFe+/B7Xdw1u7K9ocrXIx+XczfAhMxrsF0THg4JPZDlOfiVgoy5lVfOtlVyPHKmBuB6c1cvhk+MdjdpPtwl3LZpf7hW6iV6/DWfZy1d0SMdIUESGeB+VlgdrNtZLbaguyQ1hrlOqh6DRoN2Vpr13bkeC3MhUAdm/uBwgC9+UgmZK0bHfTpfHAD73oL9Sc/h2trqPaq5Hxz2ht9lTGfT3DmarVd2N9O9mrqwMdbacO1a7B2G7W0KuIkN0/Y54H5EGg6DPQO4ckD9M52st1ddZbhl38pwydv/1A0LYVyHnnOCfMhMA6huyfipI119NaWWKDWqJVV1Ed/LuKkSsNoOK+G7P08MD8L7O5KlyEMhRxXSWRaLKNK1UzC7uRpwxwxHwLDADa+Ru/vyFoPV6JLBVCrSYPWqKdzy5svXovAJPeLQuh1od8X6yqZC53sLIMz303tOVK8ngVaicRkgH76hPiwi3NzDZpNox5zzHIdJ+/vnRFej8BkRn0IkwnxOMDxTIcdI0IqfP/bKXN8N16JQG23RliM++jtp+ivvyTYPSYe+xSWl+H22+msQmeVXB5xdnhFC8ys/ACZ4zvchsM9Yt/UP6t1GXkGIbFUzS3wDHFqArVdqJNZHB5/9Vv0P/w9AKUf3ZMe3w9+LMoyKwmsts7gz85h8QoWqJMBzMQCnz1k/ddfsbRcpf53H8PNO6ib90Tbaa0ulweeKX4vgTPN2ThCD47QR3vmhzG6e4RSCrdegrv3UWtvo8r12XthnbxgfZb41k9XZ886c0uz3luHza+Tze8cHMjiv1YVde/HUqjO20TnipcSOHsvull1FclMA/1j+yZwXdqrdby1jhSpF3Qx+GXGCQLTm06i2Xtj/QnsbqG3NtJ7ZEslqr/8Y9Tdd5NhlDxhP1+ctMDsLEMUiKtM9reY27ysa61UUI2m7OR0L8f+zTcNJwmMQ5FFBL4s2jErrpgM5dVLf0Wt3JC0ob0ic+o5zh0vIdBcdBj6YDYl6WAiK/x1nBKoFNRqqKVVVK2ZBy4XhJMETsfo3j4Muui9DbNM3FzB3Wyj6i1ZsANw6x0ZxrR3x+Y4d8wQqM3SHd07EHnE3raceXZvy+pNKZXZlfztFSmVzfFa7RyvhoRAO4ipx33YfCb7p/vHaURaKEK9JcVpS2C9nTdqLxipBZp0QR/twrOH6CiCqbnl2XVRgGpdQy3fkmd2db+TW99FwksV1YFEnMNjdK+XLJbDceS1VDHuspB2h/KhlAuHl14YNZRC9fY6emMD1Wqhbt4U11mpScRZbZibmvMNSYsCL7kvfTKA430YD4UUzxPiSiWoVCV4sWsdLfLI88LhMThEhwH6k3+RRXNBANeuodZuwP0PRJRUromus1TN870Fg6fHA1n9sb0B6+vQakG7DfWG7KEulMVt2uUDuctcKHj6v/4NJmOCTz6l+3CX63/9U9RP/0wizpU7s5twZ24+ybEI8PSThzCdcvxol/WNAdeVQt15X9TUlUa6ut8uX82xUPD8z75EBxFaQ6tVgk4HVW3K6n6vwMyiudx9Lhy89f/ZxFFQqXgsd0qo5RWRwpvraiBvzC4ynJ3uhP3ulGLJpbzWkuBFpVL4nLzFhvOb3ojfjSaUmmVKH96HlVv5qqs3CM5UayaxRjkKCoU8UHnD8P8SwOyeOzosfAAAAABJRU5ErkJggg==\" id=\"imageb7d1b9bbd5\" transform=\"scale(1 -1)translate(0 -112)\" x=\"40.603125\" y=\"-9.483219\" width=\"112\" height=\"112\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m6bcb2fdf77\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m6bcb2fdf77\" x=\"41.719125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(38.537875 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m6bcb2fdf77\" x=\"86.359125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 20 -->\n","      <g transform=\"translate(79.996625 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_3\">\n","      <g>\n","       <use xlink:href=\"#m6bcb2fdf77\" x=\"130.999125\" y=\"121.483219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 40 -->\n","      <g transform=\"translate(124.636625 136.081656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_4\">\n","     <!-- Sorted training inputs -->\n","     <g transform=\"translate(41.889844 149.759781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-53\" d=\"M 3425 4513 \n","L 3425 3897 \n","Q 3066 4069 2747 4153 \n","Q 2428 4238 2131 4238 \n","Q 1616 4238 1336 4038 \n","Q 1056 3838 1056 3469 \n","Q 1056 3159 1242 3001 \n","Q 1428 2844 1947 2747 \n","L 2328 2669 \n","Q 3034 2534 3370 2195 \n","Q 3706 1856 3706 1288 \n","Q 3706 609 3251 259 \n","Q 2797 -91 1919 -91 \n","Q 1588 -91 1214 -16 \n","Q 841 59 441 206 \n","L 441 856 \n","Q 825 641 1194 531 \n","Q 1563 422 1919 422 \n","Q 2459 422 2753 634 \n","Q 3047 847 3047 1241 \n","Q 3047 1584 2836 1778 \n","Q 2625 1972 2144 2069 \n","L 1759 2144 \n","Q 1053 2284 737 2584 \n","Q 422 2884 422 3419 \n","Q 422 4038 858 4394 \n","Q 1294 4750 2059 4750 \n","Q 2388 4750 2728 4690 \n","Q 3069 4631 3425 4513 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n","Q 1497 1759 1228 1600 \n","Q 959 1441 959 1056 \n","Q 959 750 1161 570 \n","Q 1363 391 1709 391 \n","Q 2188 391 2477 730 \n","Q 2766 1069 2766 1631 \n","L 2766 1759 \n","L 2194 1759 \n","z\n","M 3341 1997 \n","L 3341 0 \n","L 2766 0 \n","L 2766 531 \n","Q 2569 213 2275 61 \n","Q 1981 -91 1556 -91 \n","Q 1019 -91 701 211 \n","Q 384 513 384 1019 \n","Q 384 1609 779 1909 \n","Q 1175 2209 1959 2209 \n","L 2766 2209 \n","L 2766 2266 \n","Q 2766 2663 2505 2880 \n","Q 2244 3097 1772 3097 \n","Q 1472 3097 1187 3025 \n","Q 903 2953 641 2809 \n","L 641 3341 \n","Q 956 3463 1253 3523 \n","Q 1550 3584 1831 3584 \n","Q 2591 3584 2966 3190 \n","Q 3341 2797 3341 1997 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \n","Q 2906 2416 2648 2759 \n","Q 2391 3103 1925 3103 \n","Q 1463 3103 1205 2759 \n","Q 947 2416 947 1791 \n","Q 947 1169 1205 825 \n","Q 1463 481 1925 481 \n","Q 2391 481 2648 825 \n","Q 2906 1169 2906 1791 \n","z\n","M 3481 434 \n","Q 3481 -459 3084 -895 \n","Q 2688 -1331 1869 -1331 \n","Q 1566 -1331 1297 -1286 \n","Q 1028 -1241 775 -1147 \n","L 775 -588 \n","Q 1028 -725 1275 -790 \n","Q 1522 -856 1778 -856 \n","Q 2344 -856 2625 -561 \n","Q 2906 -266 2906 331 \n","L 2906 616 \n","Q 2728 306 2450 153 \n","Q 2172 0 1784 0 \n","Q 1141 0 747 490 \n","Q 353 981 353 1791 \n","Q 353 2603 747 3093 \n","Q 1141 3584 1784 3584 \n","Q 2172 3584 2450 3431 \n","Q 2728 3278 2906 2969 \n","L 2906 3500 \n","L 3481 3500 \n","L 3481 434 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-53\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"400.976562\"/>\n","      <use xlink:href=\"#DejaVuSans-61\" x=\"442.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"503.369141\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"531.152344\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"594.53125\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"622.314453\"/>\n","      <use xlink:href=\"#DejaVuSans-67\" x=\"685.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"749.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"780.957031\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"808.740234\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"872.119141\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"935.595703\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"998.974609\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"1038.183594\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_4\">\n","      <defs>\n","       <path id=\"m5dd4cac33f\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m5dd4cac33f\" x=\"40.603125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 0 -->\n","      <g transform=\"translate(27.240625 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m5dd4cac33f\" x=\"40.603125\" y=\"33.319219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 10 -->\n","      <g transform=\"translate(20.878125 37.118437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m5dd4cac33f\" x=\"40.603125\" y=\"55.639219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 20 -->\n","      <g transform=\"translate(20.878125 59.438437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m5dd4cac33f\" x=\"40.603125\" y=\"77.959219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 30 -->\n","      <g transform=\"translate(20.878125 81.758437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m5dd4cac33f\" x=\"40.603125\" y=\"100.279219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 40 -->\n","      <g transform=\"translate(20.878125 104.078437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Sorted testing inputs -->\n","     <g transform=\"translate(14.798438 118.160562)rotate(-90)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-53\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"63.476562\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"124.658203\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"165.771484\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"204.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"266.503906\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"329.980469\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"361.767578\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"400.976562\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"462.5\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"514.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"553.808594\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"581.591797\"/>\n","      <use xlink:href=\"#DejaVuSans-67\" x=\"644.970703\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"708.447266\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"740.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"768.017578\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"831.396484\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"894.873047\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"958.251953\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"997.460938\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 40.603125 121.483219 \n","L 40.603125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 152.203125 121.483219 \n","L 152.203125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 40.603125 121.483219 \n","L 152.203125 121.483219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 40.603125 9.883219 \n","L 152.203125 9.883219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 159.178125 106.453219 \n","L 163.255125 106.453219 \n","L 163.255125 24.913219 \n","L 159.178125 24.913219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#pbd619d377f)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABRCAYAAAD1sgc6AAAAnklEQVR4nJ2Suw7CQAwEjZT//1QqCnR+0XKzJxmSLqPx7krJo1/Ptq/nsgzbQRVBDqBH4wCkhTtkWDhqR8OSIHjii6H/Z2jtaLD2EDpm3DCkNvldftgB0GJIqM/TBfAfE+AAJcaSpZJRg1Fs0QyCjN5BRA0gkycEmTyRFhox7simsb/blSbGDWCDcdgB4MxwGu8CWAJ4shgqJ9IiBms/jwXJt9gA8G4AAAAASUVORK5CYII=\" id=\"imagec1c03f8afa\" transform=\"scale(1 -1)translate(0 -81)\" x=\"159\" y=\"-25\" width=\"4\" height=\"81\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_9\">\n","      <defs>\n","       <path id=\"mb287b00bb5\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mb287b00bb5\" x=\"163.255125\" y=\"106.453219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(170.255125 110.252437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mb287b00bb5\" x=\"163.255125\" y=\"84.071293\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(170.255125 87.870512)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#mb287b00bb5\" x=\"163.255125\" y=\"61.689367\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(170.255125 65.488586)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#mb287b00bb5\" x=\"163.255125\" y=\"39.307441\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 0.6 -->\n","      <g transform=\"translate(170.255125 43.10666)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-36\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 159.178125 106.453219 \n","L 161.216625 106.453219 \n","L 163.255125 106.453219 \n","L 163.255125 24.913219 \n","L 161.216625 24.913219 \n","L 159.178125 24.913219 \n","L 159.178125 106.453219 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p59be1a30fe\">\n","   <rect x=\"40.603125\" y=\"9.883219\" width=\"111.6\" height=\"111.6\"/>\n","  </clipPath>\n","  <clipPath id=\"pbd619d377f\">\n","   <rect x=\"159.178125\" y=\"24.913219\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(net.attention_weights.unsqueeze(0).unsqueeze(0),\n","                  xlabel='Sorted training inputs',\n","                  ylabel='Sorted testing inputs')"],"id":"2ba62905"},{"cell_type":"markdown","metadata":{"origin_pos":53,"id":"bfb0e7c9"},"source":["## 小结\n","\n","* Nadaraya-Watson核回归是具有注意力机制的机器学习范例。\n","* Nadaraya-Watson核回归的注意力汇聚是对训练数据中输出的加权平均。从注意力的角度来看，分配给每个值的注意力权重取决于将值所对应的键和查询作为输入的函数。\n","* 注意力汇聚可以分为非参数型和带参数型。\n","\n","## 练习\n","\n","1. 增加训练数据的样本数量，你能否得到更好的非参数的Nadaraya-Watson核回归模型？\n","1. 在带参数的注意力汇聚的实验中学习得到的参数$w$的价值是什么？为什么在可视化注意力权重时，它会使加权区域更加尖锐？\n","1. 如何将超参数添加到非参数的Nadaraya-Watson核回归中以实现更好地预测结果？\n","1. 为本节的核回归设计一个新的带参数的注意力汇聚模型。训练这个新模型并可视化其注意力权重。\n"],"id":"bfb0e7c9"},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"be6bb20f"},"source":["# 注意力评分函数\n",":label:`sec_attention-scoring-functions`\n","\n","在 :numref:`sec_nadaraya-watson`中，\n","我们使用高斯核来对查询和键之间的关系建模。\n","我们可以将 :eqref:`eq_nadaraya-watson-gaussian`中的\n","高斯核指数部分视为*注意力评分函数*（attention scoring function），\n","简称*评分函数*（scoring function），\n","然后把这个函数的输出结果输入到softmax函数中进行运算。\n","通过上述步骤，我们将得到与键对应的值的概率分布（即注意力权重）。\n","最后，注意力汇聚的输出就是基于这些注意力权重的值的加权和。\n","\n","从宏观来看，我们可以使用上述算法来实现\n"," :numref:`fig_qkv`中的注意力机制框架。\n"," :numref:`fig_attention_output`说明了\n","如何将注意力汇聚的输出计算成为值的加权和，\n","其中$a$表示注意力评分函数。\n","由于注意力权重是概率分布，\n","因此加权和其本质上是加权平均值。\n","\n","![计算注意力汇聚的输出为值的加权和](../img/attention-output.svg)\n",":label:`fig_attention_output`\n","\n","用数学语言描述，假设有一个查询\n","$\\mathbf{q} \\in \\mathbb{R}^q$和\n","$m$个“键－值”对\n","$(\\mathbf{k}_1, \\mathbf{v}_1), \\ldots, (\\mathbf{k}_m, \\mathbf{v}_m)$，\n","其中$\\mathbf{k}_i \\in \\mathbb{R}^k$，$\\mathbf{v}_i \\in \\mathbb{R}^v$。\n","注意力汇聚函数$f$就被表示成值的加权和：\n","\n","$$f(\\mathbf{q}, (\\mathbf{k}_1, \\mathbf{v}_1), \\ldots, (\\mathbf{k}_m, \\mathbf{v}_m)) = \\sum_{i=1}^m \\alpha(\\mathbf{q}, \\mathbf{k}_i) \\mathbf{v}_i \\in \\mathbb{R}^v,$$\n",":eqlabel:`eq_attn-pooling`\n","\n","其中查询$\\mathbf{q}$和键$\\mathbf{k}_i$的注意力权重（标量）\n","是通过注意力评分函数$a$ 将两个向量映射成标量，\n","再经过softmax运算得到的：\n","\n","$$\\alpha(\\mathbf{q}, \\mathbf{k}_i) = \\mathrm{softmax}(a(\\mathbf{q}, \\mathbf{k}_i)) = \\frac{\\exp(a(\\mathbf{q}, \\mathbf{k}_i))}{\\sum_{j=1}^m \\exp(a(\\mathbf{q}, \\mathbf{k}_j))} \\in \\mathbb{R}.$$\n",":eqlabel:`eq_attn-scoring-alpha`\n","\n","正如我们所看到的，选择不同的注意力评分函数$a$会导致不同的注意力汇聚操作。\n","在本节中，我们将介绍两个流行的评分函数，稍后将用他们来实现更复杂的注意力机制。\n"],"id":"be6bb20f"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:18.974881Z","iopub.status.busy":"2022-07-31T02:24:18.974405Z","iopub.status.idle":"2022-07-31T02:24:20.820303Z","shell.execute_reply":"2022-07-31T02:24:20.819606Z"},"origin_pos":2,"tab":["pytorch"],"id":"7fa04b9c"},"outputs":[],"source":["import math\n","import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"7fa04b9c"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"20f5c368"},"source":["## [**掩蔽softmax操作**]\n","\n","正如上面提到的，softmax操作用于输出一个概率分布作为注意力权重。\n","在某些情况下，并非所有的值都应该被纳入到注意力汇聚中。\n","例如，为了在 :numref:`sec_machine_translation`中高效处理小批量数据集，\n","某些文本序列被填充了没有意义的特殊词元。\n","为了仅将有意义的词元作为值来获取注意力汇聚，\n","我们可以指定一个有效序列长度（即词元的个数），\n","以便在计算softmax时过滤掉超出指定范围的位置。\n","通过这种方式，我们可以在下面的`masked_softmax`函数中\n","实现这样的*掩蔽softmax操作*（masked softmax operation），\n","其中任何超出有效长度的位置都被掩蔽并置为0。\n"],"id":"20f5c368"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.823987Z","iopub.status.busy":"2022-07-31T02:24:20.823603Z","iopub.status.idle":"2022-07-31T02:24:20.829319Z","shell.execute_reply":"2022-07-31T02:24:20.828707Z"},"origin_pos":6,"tab":["pytorch"],"id":"123085c6"},"outputs":[],"source":["#@save\n","def masked_softmax(X, valid_lens):\n","    \"\"\"通过在最后一个轴上掩蔽元素来执行softmax操作\"\"\"\n","    # X:3D张量，valid_lens:1D或2D张量\n","    if valid_lens is None:\n","        return nn.functional.softmax(X, dim=-1)\n","    else:\n","        shape = X.shape\n","        if valid_lens.dim() == 1:\n","            valid_lens = torch.repeat_interleave(valid_lens, shape[1])\n","        else:\n","            valid_lens = valid_lens.reshape(-1)\n","        # 最后一轴上被掩蔽的元素使用一个非常大的负值替换，从而其softmax输出为0\n","        X = d2l.sequence_mask(X.reshape(-1, shape[-1]), valid_lens,\n","                              value=-1e6)\n","        return nn.functional.softmax(X.reshape(shape), dim=-1)"],"id":"123085c6"},{"cell_type":"markdown","metadata":{"origin_pos":8,"id":"d01b3acd"},"source":["为了[**演示此函数是如何工作**]的，\n","考虑由两个$2 \\times 4$矩阵表示的样本，\n","这两个样本的有效长度分别为$2$和$3$。\n","经过掩蔽softmax操作，超出有效长度的值都被掩蔽为0。\n"],"id":"d01b3acd"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.832151Z","iopub.status.busy":"2022-07-31T02:24:20.831823Z","iopub.status.idle":"2022-07-31T02:24:20.841539Z","shell.execute_reply":"2022-07-31T02:24:20.840954Z"},"origin_pos":10,"tab":["pytorch"],"id":"3de66cb8","outputId":"25eeded6-db90-48d2-dc39-0dd3a3883f1c"},"outputs":[{"data":{"text/plain":["tensor([[[0.5423, 0.4577, 0.0000, 0.0000],\n","         [0.6133, 0.3867, 0.0000, 0.0000]],\n","\n","        [[0.3324, 0.2348, 0.4329, 0.0000],\n","         [0.2444, 0.3943, 0.3613, 0.0000]]])"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["masked_softmax(torch.rand(2, 2, 4), torch.tensor([2, 3]))"],"id":"3de66cb8"},{"cell_type":"markdown","metadata":{"origin_pos":12,"id":"8888b186"},"source":["同样，我们也可以使用二维张量，为矩阵样本中的每一行指定有效长度。\n"],"id":"8888b186"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.844471Z","iopub.status.busy":"2022-07-31T02:24:20.844133Z","iopub.status.idle":"2022-07-31T02:24:20.849664Z","shell.execute_reply":"2022-07-31T02:24:20.849088Z"},"origin_pos":14,"tab":["pytorch"],"id":"8a27f397","outputId":"3a3ca994-461a-4cba-e1cf-ef6709298fca"},"outputs":[{"data":{"text/plain":["tensor([[[1.0000, 0.0000, 0.0000, 0.0000],\n","         [0.4142, 0.3582, 0.2275, 0.0000]],\n","\n","        [[0.5565, 0.4435, 0.0000, 0.0000],\n","         [0.3305, 0.2070, 0.2827, 0.1798]]])"]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["masked_softmax(torch.rand(2, 2, 4), torch.tensor([[1, 3], [2, 4]]))"],"id":"8a27f397"},{"cell_type":"markdown","metadata":{"origin_pos":16,"id":"f5fcd345"},"source":["## [**加性注意力**]\n",":label:`subsec_additive-attention`\n","\n","一般来说，当查询和键是不同长度的矢量时，\n","我们可以使用加性注意力作为评分函数。\n","给定查询$\\mathbf{q} \\in \\mathbb{R}^q$和\n","键$\\mathbf{k} \\in \\mathbb{R}^k$，\n","*加性注意力*（additive attention）的评分函数为\n","\n","$$a(\\mathbf q, \\mathbf k) = \\mathbf w_v^\\top \\text{tanh}(\\mathbf W_q\\mathbf q + \\mathbf W_k \\mathbf k) \\in \\mathbb{R},$$\n",":eqlabel:`eq_additive-attn`\n","\n","其中可学习的参数是$\\mathbf W_q\\in\\mathbb R^{h\\times q}$、\n","$\\mathbf W_k\\in\\mathbb R^{h\\times k}$和\n","$\\mathbf w_v\\in\\mathbb R^{h}$。\n","如 :eqref:`eq_additive-attn`所示，\n","将查询和键连结起来后输入到一个多层感知机（MLP）中，\n","感知机包含一个隐藏层，其隐藏单元数是一个超参数$h$。\n","通过使用$\\tanh$作为激活函数，并且禁用偏置项。\n","\n","下面我们来实现加性注意力。\n"],"id":"f5fcd345"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.852714Z","iopub.status.busy":"2022-07-31T02:24:20.852276Z","iopub.status.idle":"2022-07-31T02:24:20.859061Z","shell.execute_reply":"2022-07-31T02:24:20.858433Z"},"origin_pos":18,"tab":["pytorch"],"id":"04c323a2"},"outputs":[],"source":["#@save\n","class AdditiveAttention(nn.Module):\n","    \"\"\"加性注意力\"\"\"\n","    def __init__(self, key_size, query_size, num_hiddens, dropout, **kwargs):\n","        super(AdditiveAttention, self).__init__(**kwargs)\n","        self.W_k = nn.Linear(key_size, num_hiddens, bias=False)\n","        self.W_q = nn.Linear(query_size, num_hiddens, bias=False)\n","        self.w_v = nn.Linear(num_hiddens, 1, bias=False)\n","        self.dropout = nn.Dropout(dropout)\n","\n","    def forward(self, queries, keys, values, valid_lens):\n","        queries, keys = self.W_q(queries), self.W_k(keys)\n","        # 在维度扩展后，\n","        # queries的形状：(batch_size，查询的个数，1，num_hidden)\n","        # key的形状：(batch_size，1，“键－值”对的个数，num_hiddens)\n","        # 使用广播方式进行求和\n","        features = queries.unsqueeze(2) + keys.unsqueeze(1)\n","        features = torch.tanh(features)\n","        # self.w_v仅有一个输出，因此从形状中移除最后那个维度。\n","        # scores的形状：(batch_size，查询的个数，“键-值”对的个数)\n","        scores = self.w_v(features).squeeze(-1)\n","        self.attention_weights = masked_softmax(scores, valid_lens)\n","        # values的形状：(batch_size，“键－值”对的个数，值的维度)\n","        return torch.bmm(self.dropout(self.attention_weights), values)"],"id":"04c323a2"},{"cell_type":"markdown","metadata":{"origin_pos":20,"id":"5a7e5041"},"source":["我们用一个小例子来[**演示上面的`AdditiveAttention`类**]，\n","其中查询、键和值的形状为（批量大小，步数或词元序列长度，特征大小），\n","实际输出为$(2,1,20)$、$(2,10,2)$和$(2,10,4)$。\n","注意力汇聚输出的形状为（批量大小，查询的步数，值的维度）。\n"],"id":"5a7e5041"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.862264Z","iopub.status.busy":"2022-07-31T02:24:20.861716Z","iopub.status.idle":"2022-07-31T02:24:20.870987Z","shell.execute_reply":"2022-07-31T02:24:20.870376Z"},"origin_pos":22,"tab":["pytorch"],"id":"5b85641d","outputId":"3dc10df4-d802-461b-d48d-eafd57258119"},"outputs":[{"data":{"text/plain":["tensor([[[ 2.0000,  3.0000,  4.0000,  5.0000]],\n","\n","        [[10.0000, 11.0000, 12.0000, 13.0000]]], grad_fn=<BmmBackward0>)"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["queries, keys = torch.normal(0, 1, (2, 1, 20)), torch.ones((2, 10, 2))\n","# values的小批量，两个值矩阵是相同的\n","values = torch.arange(40, dtype=torch.float32).reshape(1, 10, 4).repeat(\n","    2, 1, 1)\n","valid_lens = torch.tensor([2, 6])\n","\n","attention = AdditiveAttention(key_size=2, query_size=20, num_hiddens=8,\n","                              dropout=0.1)\n","attention.eval()\n","attention(queries, keys, values, valid_lens)"],"id":"5b85641d"},{"cell_type":"markdown","metadata":{"origin_pos":24,"id":"013777c3"},"source":["尽管加性注意力包含了可学习的参数，但由于本例子中每个键都是相同的，\n","所以[**注意力权重**]是均匀的，由指定的有效长度决定。\n"],"id":"013777c3"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:20.873957Z","iopub.status.busy":"2022-07-31T02:24:20.873429Z","iopub.status.idle":"2022-07-31T02:24:21.043206Z","shell.execute_reply":"2022-07-31T02:24:21.042533Z"},"origin_pos":25,"tab":["pytorch"],"id":"d6e1da71","outputId":"5e1a21db-b2c4-4ccd-87f0-d74e2b0ebc9d"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"186.99575pt\" height=\"101.818906pt\" viewBox=\"0 0 186.99575 101.818906\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:24:21.005962</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M -0 101.818906 \n","L 186.99575 101.818906 \n","L 186.99575 0 \n","L -0 0 \n","L -0 101.818906 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 59.13 \n","L 145.840625 59.13 \n","L 145.840625 36.81 \n","L 34.240625 36.81 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p936ab42291)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHAAAAAXCAYAAADTEcupAAAAeElEQVR4nO3YsQmAQBAF0X+aWp8tGFqDXZjZnC2YCV5uJnIcA/MKWBaGTbbcx/ZESZJxXnuv8NnQewH9Y0A4A8IZEM6AcAaEMyCcAeEMCGdAOAPClSVTk1/ofp0txurFC4QzIJwB4QwIZ0A4A8IZEM6AcAaEMyBcBc2IB/NA+hblAAAAAElFTkSuQmCC\" id=\"image4461ba1d47\" transform=\"scale(1 -1)translate(0 -23)\" x=\"34.240625\" y=\"-36.13\" width=\"112\" height=\"23\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m5421ebdec8\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m5421ebdec8\" x=\"39.820625\" y=\"59.13\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(36.639375 73.728437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m5421ebdec8\" x=\"95.620625\" y=\"59.13\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 5 -->\n","      <g transform=\"translate(92.439375 73.728437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Keys -->\n","     <g transform=\"translate(78.371094 87.406562)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"mc174a03380\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mc174a03380\" x=\"34.240625\" y=\"42.39\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 46.189219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#mc174a03380\" x=\"34.240625\" y=\"53.55\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 1 -->\n","      <g transform=\"translate(20.878125 57.349219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_6\">\n","     <!-- Queries -->\n","     <g transform=\"translate(14.798437 67.277031)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 59.13 \n","L 34.240625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 145.840625 59.13 \n","L 145.840625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 59.13 \n","L 145.840625 59.13 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 36.81 \n","L 145.840625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 152.815625 88.74 \n","L 156.892625 88.74 \n","L 156.892625 7.2 \n","L 152.815625 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#pa3aa37d7a6)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABSCAYAAABzJnWUAAAAm0lEQVR4nJ2SOw7CUBADHxL3vyoNBeyXFsZIFqQcje1NlMveb3venuuZPg6MMXbKdvxcqqASoDG7+TSG7xBjm5GSSLgVjXiDQO4Izvq39SsepHxC/g5/lLJDjA2C4mzKHQ5MjjF01q50obR7P0E1jYIhkZRSgmKk7UoNI8tZgiLA6hdDI0cM1yF3BE//YqA0xCB4SClB8FK5g6UvE4PMuTPJ8jwAAAAASUVORK5CYII=\" id=\"imagedea5214d8f\" transform=\"scale(1 -1)translate(0 -82)\" x=\"153\" y=\"-6\" width=\"4\" height=\"82\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <defs>\n","       <path id=\"mac8df1bbf8\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mac8df1bbf8\" x=\"156.892625\" y=\"88.74\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(163.892625 92.539219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#mac8df1bbf8\" x=\"156.892625\" y=\"56.124\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(163.892625 59.923219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#mac8df1bbf8\" x=\"156.892625\" y=\"23.508\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(163.892625 27.307219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 152.815625 88.74 \n","L 154.854125 88.74 \n","L 156.892625 88.74 \n","L 156.892625 7.2 \n","L 154.854125 7.2 \n","L 152.815625 7.2 \n","L 152.815625 88.74 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p936ab42291\">\n","   <rect x=\"34.240625\" y=\"36.81\" width=\"111.6\" height=\"22.32\"/>\n","  </clipPath>\n","  <clipPath id=\"pa3aa37d7a6\">\n","   <rect x=\"152.815625\" y=\"7.2\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),\n","                  xlabel='Keys', ylabel='Queries')"],"id":"d6e1da71"},{"cell_type":"markdown","metadata":{"origin_pos":26,"id":"52aff1c1"},"source":["## [**缩放点积注意力**]\n","\n","使用点积可以得到计算效率更高的评分函数，\n","但是点积操作要求查询和键具有相同的长度$d$。\n","假设查询和键的所有元素都是独立的随机变量，\n","并且都满足零均值和单位方差，\n","那么两个向量的点积的均值为$0$，方差为$d$。\n","为确保无论向量长度如何，\n","点积的方差在不考虑向量长度的情况下仍然是$1$，\n","我们将点积除以$\\sqrt{d}$，\n","则*缩放点积注意力*（scaled dot-product attention）评分函数为：\n","\n","$$a(\\mathbf q, \\mathbf k) = \\mathbf{q}^\\top \\mathbf{k}  /\\sqrt{d}.$$\n","\n","在实践中，我们通常从小批量的角度来考虑提高效率，\n","例如基于$n$个查询和$m$个键－值对计算注意力，\n","其中查询和键的长度为$d$，值的长度为$v$。\n","查询$\\mathbf Q\\in\\mathbb R^{n\\times d}$、\n","键$\\mathbf K\\in\\mathbb R^{m\\times d}$和\n","值$\\mathbf V\\in\\mathbb R^{m\\times v}$的缩放点积注意力是：\n","\n","$$ \\mathrm{softmax}\\left(\\frac{\\mathbf Q \\mathbf K^\\top }{\\sqrt{d}}\\right) \\mathbf V \\in \\mathbb{R}^{n\\times v}.$$\n",":eqlabel:`eq_softmax_QK_V`\n","\n","在下面的缩放点积注意力的实现中，我们使用了暂退法进行模型正则化。\n"],"id":"52aff1c1"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:21.046386Z","iopub.status.busy":"2022-07-31T02:24:21.045912Z","iopub.status.idle":"2022-07-31T02:24:21.051608Z","shell.execute_reply":"2022-07-31T02:24:21.050930Z"},"origin_pos":28,"tab":["pytorch"],"id":"6450ece3"},"outputs":[],"source":["#@save\n","class DotProductAttention(nn.Module):\n","    \"\"\"缩放点积注意力\"\"\"\n","    def __init__(self, dropout, **kwargs):\n","        super(DotProductAttention, self).__init__(**kwargs)\n","        self.dropout = nn.Dropout(dropout)\n","\n","    # queries的形状：(batch_size，查询的个数，d)\n","    # keys的形状：(batch_size，“键－值”对的个数，d)\n","    # values的形状：(batch_size，“键－值”对的个数，值的维度)\n","    # valid_lens的形状:(batch_size，)或者(batch_size，查询的个数)\n","    def forward(self, queries, keys, values, valid_lens=None):\n","        d = queries.shape[-1]\n","        # 设置transpose_b=True为了交换keys的最后两个维度\n","        scores = torch.bmm(queries, keys.transpose(1,2)) / math.sqrt(d)\n","        self.attention_weights = masked_softmax(scores, valid_lens)\n","        return torch.bmm(self.dropout(self.attention_weights), values)"],"id":"6450ece3"},{"cell_type":"markdown","metadata":{"origin_pos":30,"id":"56dcfba5"},"source":["为了[**演示上述的`DotProductAttention`类**]，\n","我们使用与先前加性注意力例子中相同的键、值和有效长度。\n","对于点积操作，我们令查询的特征维度与键的特征维度大小相同。\n"],"id":"56dcfba5"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:21.054610Z","iopub.status.busy":"2022-07-31T02:24:21.054065Z","iopub.status.idle":"2022-07-31T02:24:21.060842Z","shell.execute_reply":"2022-07-31T02:24:21.060244Z"},"origin_pos":32,"tab":["pytorch"],"id":"068a265b","outputId":"cb00a591-4e16-466c-8d7f-1fe0644f56a5"},"outputs":[{"data":{"text/plain":["tensor([[[ 2.0000,  3.0000,  4.0000,  5.0000]],\n","\n","        [[10.0000, 11.0000, 12.0000, 13.0000]]])"]},"execution_count":9,"metadata":{},"output_type":"execute_result"}],"source":["queries = torch.normal(0, 1, (2, 1, 2))\n","attention = DotProductAttention(dropout=0.5)\n","attention.eval()\n","attention(queries, keys, values, valid_lens)"],"id":"068a265b"},{"cell_type":"markdown","metadata":{"origin_pos":34,"id":"d2fabc61"},"source":["与加性注意力演示相同，由于键包含的是相同的元素，\n","而这些元素无法通过任何查询进行区分，因此获得了[**均匀的注意力权重**]。\n"],"id":"d2fabc61"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:24:21.063642Z","iopub.status.busy":"2022-07-31T02:24:21.063446Z","iopub.status.idle":"2022-07-31T02:24:21.208314Z","shell.execute_reply":"2022-07-31T02:24:21.207661Z"},"origin_pos":35,"tab":["pytorch"],"id":"a00a1cd1","outputId":"60266380-0d96-40bc-e7b5-2fa03245a263"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"186.99575pt\" height=\"101.818906pt\" viewBox=\"0 0 186.99575 101.818906\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:24:21.174397</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M -0 101.818906 \n","L 186.99575 101.818906 \n","L 186.99575 0 \n","L -0 0 \n","L -0 101.818906 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 59.13 \n","L 145.840625 59.13 \n","L 145.840625 36.81 \n","L 34.240625 36.81 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p7a42d87a55)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHAAAAAXCAYAAADTEcupAAAAeElEQVR4nO3YsQmAQBAF0X+aWp8tGFqDXZjZnC2YCV5uJnIcA/MKWBaGTbbcx/ZESZJxXnuv8NnQewH9Y0A4A8IZEM6AcAaEMyCcAeEMCGdAOAPClSVTk1/ofp0txurFC4QzIJwB4QwIZ0A4A8IZEM6AcAaEMyBcBc2IB/NA+hblAAAAAElFTkSuQmCC\" id=\"imageabe24f62aa\" transform=\"scale(1 -1)translate(0 -23)\" x=\"34.240625\" y=\"-36.13\" width=\"112\" height=\"23\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m665217bb42\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m665217bb42\" x=\"39.820625\" y=\"59.13\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(36.639375 73.728437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m665217bb42\" x=\"95.620625\" y=\"59.13\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 5 -->\n","      <g transform=\"translate(92.439375 73.728437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Keys -->\n","     <g transform=\"translate(78.371094 87.406562)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"181.279297\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"mdf27f03b54\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mdf27f03b54\" x=\"34.240625\" y=\"42.39\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 46.189219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#mdf27f03b54\" x=\"34.240625\" y=\"53.55\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 1 -->\n","      <g transform=\"translate(20.878125 57.349219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_6\">\n","     <!-- Queries -->\n","     <g transform=\"translate(14.798437 67.277031)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"272.509766\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"334.033203\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 59.13 \n","L 34.240625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 145.840625 59.13 \n","L 145.840625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 59.13 \n","L 145.840625 59.13 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 36.81 \n","L 145.840625 36.81 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 152.815625 88.74 \n","L 156.892625 88.74 \n","L 156.892625 7.2 \n","L 152.815625 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#p8e92fe6e87)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABSCAYAAABzJnWUAAAAm0lEQVR4nJ2SOw7CUBADHxL3vyoNBeyXFsZIFqQcje1NlMveb3venuuZPg6MMXbKdvxcqqASoDG7+TSG7xBjm5GSSLgVjXiDQO4Izvq39SsepHxC/g5/lLJDjA2C4mzKHQ5MjjF01q50obR7P0E1jYIhkZRSgmKk7UoNI8tZgiLA6hdDI0cM1yF3BE//YqA0xCB4SClB8FK5g6UvE4PMuTPJ8jwAAAAASUVORK5CYII=\" id=\"image1a20eb6722\" transform=\"scale(1 -1)translate(0 -82)\" x=\"153\" y=\"-6\" width=\"4\" height=\"82\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <defs>\n","       <path id=\"m430e20a882\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m430e20a882\" x=\"156.892625\" y=\"88.74\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(163.892625 92.539219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m430e20a882\" x=\"156.892625\" y=\"56.124\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(163.892625 59.923219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m430e20a882\" x=\"156.892625\" y=\"23.508\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(163.892625 27.307219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 152.815625 88.74 \n","L 154.854125 88.74 \n","L 156.892625 88.74 \n","L 156.892625 7.2 \n","L 154.854125 7.2 \n","L 152.815625 7.2 \n","L 152.815625 88.74 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p7a42d87a55\">\n","   <rect x=\"34.240625\" y=\"36.81\" width=\"111.6\" height=\"22.32\"/>\n","  </clipPath>\n","  <clipPath id=\"p8e92fe6e87\">\n","   <rect x=\"152.815625\" y=\"7.2\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(attention.attention_weights.reshape((1, 1, 2, 10)),\n","                  xlabel='Keys', ylabel='Queries')"],"id":"a00a1cd1"},{"cell_type":"markdown","metadata":{"origin_pos":36,"id":"459138b8"},"source":["## 小结\n","\n","* 将注意力汇聚的输出计算可以作为值的加权平均，选择不同的注意力评分函数会带来不同的注意力汇聚操作。\n","* 当查询和键是不同长度的矢量时，可以使用可加性注意力评分函数。当它们的长度相同时，使用缩放的“点－积”注意力评分函数的计算效率更高。\n","\n","## 练习\n","\n","1. 修改小例子中的键，并且可视化注意力权重。可加性注意力和缩放的“点－积”注意力是否仍然产生相同的结果？为什么？\n","1. 只使用矩阵乘法，你能否为具有不同矢量长度的查询和键设计新的评分函数？\n","1. 当查询和键具有相同的矢量长度时，矢量求和作为评分函数是否比“点－积”更好？为什么？\n"],"id":"459138b8"},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"94be76a7"},"source":["# Bahdanau 注意力\n",":label:`sec_seq2seq_attention`\n","\n","我们在 :numref:`sec_seq2seq`中探讨了机器翻译问题：\n","通过设计一个基于两个循环神经网络的编码器-解码器架构，\n","用于序列到序列学习。\n","具体来说，循环神经网络编码器将长度可变的序列转换为固定形状的上下文变量，\n","然后循环神经网络解码器根据生成的词元和上下文变量\n","按词元生成输出（目标）序列词元。\n","然而，即使并非所有输入（源）词元都对解码某个词元都有用，\n","在每个解码步骤中仍使用编码*相同*的上下文变量。\n","有什么方法能改变上下文变量呢？\n","\n","我们试着从 :cite:`Graves.2013`中找到灵感：\n","在为给定文本序列生成手写的挑战中，\n","Graves设计了一种可微注意力模型，\n","将文本字符与更长的笔迹对齐，\n","其中对齐方式仅向一个方向移动。\n","受学习对齐想法的启发，Bahdanau等人提出了一个没有严格单向对齐限制的\n","可微注意力模型 :cite:`Bahdanau.Cho.Bengio.2014`。\n","在预测词元时，如果不是所有输入词元都相关，模型将仅对齐（或参与）输入序列中与当前预测相关的部分。这是通过将上下文变量视为注意力集中的输出来实现的。\n","\n","## 模型\n","\n","下面描述的Bahdanau注意力模型\n","将遵循 :numref:`sec_seq2seq`中的相同符号表达。\n","这个新的基于注意力的模型与 :numref:`sec_seq2seq`中的模型相同，\n","只不过 :eqref:`eq_seq2seq_s_t`中的上下文变量$\\mathbf{c}$\n","在任何解码时间步$t'$都会被$\\mathbf{c}_{t'}$替换。\n","假设输入序列中有$T$个词元，\n","解码时间步$t'$的上下文变量是注意力集中的输出：\n","\n","$$\\mathbf{c}_{t'} = \\sum_{t=1}^T \\alpha(\\mathbf{s}_{t' - 1}, \\mathbf{h}_t) \\mathbf{h}_t,$$\n","\n","其中，时间步$t' - 1$时的解码器隐状态$\\mathbf{s}_{t' - 1}$是查询，\n","编码器隐状态$\\mathbf{h}_t$既是键，也是值，\n","注意力权重$\\alpha$是使用 :eqref:`eq_attn-scoring-alpha`\n","所定义的加性注意力打分函数计算的。\n","\n","与 :numref:`fig_seq2seq_details`中的循环神经网络编码器-解码器架构略有不同，\n"," :numref:`fig_s2s_attention_details`描述了Bahdanau注意力的架构。\n","\n","![一个带有Bahdanau注意力的循环神经网络编码器-解码器模型](../img/seq2seq-attention-details.svg)\n",":label:`fig_s2s_attention_details`\n"],"id":"94be76a7"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:33:01.763010Z","iopub.status.busy":"2022-07-31T02:33:01.762536Z","iopub.status.idle":"2022-07-31T02:33:03.691242Z","shell.execute_reply":"2022-07-31T02:33:03.690502Z"},"origin_pos":2,"tab":["pytorch"],"id":"3cd58dec"},"outputs":[],"source":["import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"3cd58dec"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"dfb90eb6"},"source":["## 定义注意力解码器\n","\n","下面我们看看如何定义Bahdanau注意力，实现循环神经网络编码器-解码器。\n","其实，我们只需重新定义解码器即可。\n","为了更方便地显示学习的注意力权重，\n","以下`AttentionDecoder`类定义了[**带有注意力机制解码器的基本接口**]。\n"],"id":"dfb90eb6"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:33:03.696197Z","iopub.status.busy":"2022-07-31T02:33:03.695792Z","iopub.status.idle":"2022-07-31T02:33:03.701075Z","shell.execute_reply":"2022-07-31T02:33:03.700236Z"},"origin_pos":5,"tab":["pytorch"],"id":"2327b25c"},"outputs":[],"source":["#@save\n","class AttentionDecoder(d2l.Decoder):\n","    \"\"\"带有注意力机制解码器的基本接口\"\"\"\n","    def __init__(self, **kwargs):\n","        super(AttentionDecoder, self).__init__(**kwargs)\n","\n","    @property\n","    def attention_weights(self):\n","        raise NotImplementedError"],"id":"2327b25c"},{"cell_type":"markdown","metadata":{"origin_pos":6,"id":"ccf8d43c"},"source":["接下来，让我们在接下来的`Seq2SeqAttentionDecoder`类中\n","[**实现带有Bahdanau注意力的循环神经网络解码器**]。\n","首先，我们初始化解码器的状态，需要下面的输入：\n","\n","1. 编码器在所有时间步的最终层隐状态，将作为注意力的键和值；\n","1. 上一时间步的编码器全层隐状态，将作为初始化解码器的隐状态；\n","1. 编码器有效长度（排除在注意力池中填充词元）。\n","\n","在每个解码时间步骤中，解码器上一个时间步的最终层隐状态将用作查询。\n","因此，注意力输出和输入嵌入都连结为循环神经网络解码器的输入。\n"],"id":"ccf8d43c"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:33:03.704122Z","iopub.status.busy":"2022-07-31T02:33:03.703732Z","iopub.status.idle":"2022-07-31T02:33:03.713087Z","shell.execute_reply":"2022-07-31T02:33:03.712486Z"},"origin_pos":8,"tab":["pytorch"],"id":"eb0d22ed"},"outputs":[],"source":["class Seq2SeqAttentionDecoder(AttentionDecoder):\n","    def __init__(self, vocab_size, embed_size, num_hiddens, num_layers,\n","                 dropout=0, **kwargs):\n","        super(Seq2SeqAttentionDecoder, self).__init__(**kwargs)\n","        self.attention = d2l.AdditiveAttention(\n","            num_hiddens, num_hiddens, num_hiddens, dropout)\n","        self.embedding = nn.Embedding(vocab_size, embed_size)\n","        self.rnn = nn.GRU(\n","            embed_size + num_hiddens, num_hiddens, num_layers,\n","            dropout=dropout)\n","        self.dense = nn.Linear(num_hiddens, vocab_size)\n","\n","    def init_state(self, enc_outputs, enc_valid_lens, *args):\n","        # outputs的形状为(batch_size，num_steps，num_hiddens).\n","        # hidden_state的形状为(num_layers，batch_size，num_hiddens)\n","        outputs, hidden_state = enc_outputs\n","        return (outputs.permute(1, 0, 2), hidden_state, enc_valid_lens)\n","\n","    def forward(self, X, state):\n","        # enc_outputs的形状为(batch_size,num_steps,num_hiddens).\n","        # hidden_state的形状为(num_layers,batch_size,\n","        # num_hiddens)\n","        enc_outputs, hidden_state, enc_valid_lens = state\n","        # 输出X的形状为(num_steps,batch_size,embed_size)\n","        X = self.embedding(X).permute(1, 0, 2)\n","        outputs, self._attention_weights = [], []\n","        for x in X:\n","            # query的形状为(batch_size,1,num_hiddens)\n","            query = torch.unsqueeze(hidden_state[-1], dim=1)\n","            # context的形状为(batch_size,1,num_hiddens)\n","            context = self.attention(\n","                query, enc_outputs, enc_outputs, enc_valid_lens)\n","            # 在特征维度上连结\n","            x = torch.cat((context, torch.unsqueeze(x, dim=1)), dim=-1)\n","            # 将x变形为(1,batch_size,embed_size+num_hiddens)\n","            out, hidden_state = self.rnn(x.permute(1, 0, 2), hidden_state)\n","            outputs.append(out)\n","            self._attention_weights.append(self.attention.attention_weights)\n","        # 全连接层变换后，outputs的形状为\n","        # (num_steps,batch_size,vocab_size)\n","        outputs = self.dense(torch.cat(outputs, dim=0))\n","        return outputs.permute(1, 0, 2), [enc_outputs, hidden_state,\n","                                          enc_valid_lens]\n","\n","    @property\n","    def attention_weights(self):\n","        return self._attention_weights"],"id":"eb0d22ed"},{"cell_type":"markdown","metadata":{"origin_pos":10,"id":"1d291e15"},"source":["接下来，我们使用包含7个时间步的4个序列输入的小批量[**测试Bahdanau注意力解码器**]。\n"],"id":"1d291e15"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:33:03.716451Z","iopub.status.busy":"2022-07-31T02:33:03.715913Z","iopub.status.idle":"2022-07-31T02:33:03.736688Z","shell.execute_reply":"2022-07-31T02:33:03.736041Z"},"origin_pos":12,"tab":["pytorch"],"id":"f7067b24","outputId":"ea62c0cb-2cdd-4adb-a847-73dca02386f2"},"outputs":[{"data":{"text/plain":["(torch.Size([4, 7, 10]), 3, torch.Size([4, 7, 16]), 2, torch.Size([4, 16]))"]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["encoder = d2l.Seq2SeqEncoder(vocab_size=10, embed_size=8, num_hiddens=16,\n","                             num_layers=2)\n","encoder.eval()\n","decoder = Seq2SeqAttentionDecoder(vocab_size=10, embed_size=8, num_hiddens=16,\n","                                  num_layers=2)\n","decoder.eval()\n","X = torch.zeros((4, 7), dtype=torch.long)  # (batch_size,num_steps)\n","state = decoder.init_state(encoder(X), None)\n","output, state = decoder(X, state)\n","output.shape, len(state), state[0].shape, len(state[1]), state[1][0].shape"],"id":"f7067b24"},{"cell_type":"markdown","metadata":{"origin_pos":14,"id":"fcdd6e15"},"source":["## [**训练**]\n","\n","与 :numref:`sec_seq2seq_training`类似，\n","我们在这里指定超参数，实例化一个带有Bahdanau注意力的编码器和解码器，\n","并对这个模型进行机器翻译训练。\n","由于新增的注意力机制，训练要比没有注意力机制的\n"," :numref:`sec_seq2seq_training`慢得多。\n"],"id":"fcdd6e15"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:33:03.739859Z","iopub.status.busy":"2022-07-31T02:33:03.739405Z","iopub.status.idle":"2022-07-31T02:34:40.180902Z","shell.execute_reply":"2022-07-31T02:34:40.180242Z"},"origin_pos":15,"tab":["pytorch"],"id":"9a755137","outputId":"cdbafb91-6d69-401f-8070-88e57352b597"},"outputs":[{"name":"stdout","output_type":"stream","text":["loss 0.020, 5845.4 tokens/sec on cuda:0\n"]},{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"262.1875pt\" height=\"180.65625pt\" viewBox=\"0 0 262.1875 180.65625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:34:40.149525</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 180.65625 \n","L 262.1875 180.65625 \n","L 262.1875 0 \n","L 0 0 \n","L 0 180.65625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 50.14375 143.1 \n","L 245.44375 143.1 \n","L 245.44375 7.2 \n","L 50.14375 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 82.69375 143.1 \n","L 82.69375 7.2 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"mbac07a4cf8\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mbac07a4cf8\" x=\"82.69375\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 50 -->\n","      <g transform=\"translate(76.33125 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 123.38125 143.1 \n","L 123.38125 7.2 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#mbac07a4cf8\" x=\"123.38125\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 100 -->\n","      <g transform=\"translate(113.8375 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 164.06875 143.1 \n","L 164.06875 7.2 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#mbac07a4cf8\" x=\"164.06875\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 150 -->\n","      <g transform=\"translate(154.525 157.698438)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 204.75625 143.1 \n","L 204.75625 7.2 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#mbac07a4cf8\" x=\"204.75625\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 200 -->\n","      <g transform=\"translate(195.2125 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 245.44375 143.1 \n","L 245.44375 7.2 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mbac07a4cf8\" x=\"245.44375\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 250 -->\n","      <g transform=\"translate(235.9 157.698438)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_6\">\n","     <!-- epoch -->\n","     <g transform=\"translate(132.565625 171.376563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n","L 3122 2828 \n","Q 2878 2963 2633 3030 \n","Q 2388 3097 2138 3097 \n","Q 1578 3097 1268 2742 \n","Q 959 2388 959 1747 \n","Q 959 1106 1268 751 \n","Q 1578 397 2138 397 \n","Q 2388 397 2633 464 \n","Q 2878 531 3122 666 \n","L 3122 134 \n","Q 2881 22 2623 -34 \n","Q 2366 -91 2075 -91 \n","Q 1284 -91 818 406 \n","Q 353 903 353 1747 \n","Q 353 2603 823 3093 \n","Q 1294 3584 2113 3584 \n","Q 2378 3584 2631 3529 \n","Q 2884 3475 3122 3366 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-65\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n","      <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 50.14375 116.149319 \n","L 245.44375 116.149319 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <defs>\n","       <path id=\"m7227202216\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m7227202216\" x=\"50.14375\" y=\"116.149319\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 0.05 -->\n","      <g transform=\"translate(20.878125 119.948538)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 50.14375 81.750496 \n","L 245.44375 81.750496 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#m7227202216\" x=\"50.14375\" y=\"81.750496\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0.10 -->\n","      <g transform=\"translate(20.878125 85.549715)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 50.14375 47.351672 \n","L 245.44375 47.351672 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#m7227202216\" x=\"50.14375\" y=\"47.351672\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0.15 -->\n","      <g transform=\"translate(20.878125 51.150891)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 50.14375 12.952849 \n","L 245.44375 12.952849 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#m7227202216\" x=\"50.14375\" y=\"12.952849\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 0.20 -->\n","      <g transform=\"translate(20.878125 16.752068)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_11\">\n","     <!-- loss -->\n","     <g transform=\"translate(14.798437 84.807812)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n","L 1178 4863 \n","L 1178 0 \n","L 603 0 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-6c\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"27.783203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"88.964844\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"141.064453\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_19\">\n","    <path d=\"M 50.14375 13.377273 \n","L 58.28125 58.529114 \n","L 66.41875 82.949822 \n","L 74.55625 99.328427 \n","L 82.69375 110.046427 \n","L 90.83125 117.77701 \n","L 98.96875 122.121946 \n","L 107.10625 126.27456 \n","L 115.24375 129.122442 \n","L 123.38125 130.796948 \n","L 131.51875 132.632819 \n","L 139.65625 133.444298 \n","L 147.79375 134.317169 \n","L 155.93125 134.774071 \n","L 164.06875 135.055275 \n","L 172.20625 135.461652 \n","L 180.34375 136.10714 \n","L 188.48125 136.44269 \n","L 196.61875 136.093256 \n","L 204.75625 136.432407 \n","L 212.89375 136.705851 \n","L 221.03125 136.463777 \n","L 229.16875 136.922727 \n","L 237.30625 136.633327 \n","L 245.44375 136.770116 \n","\" clip-path=\"url(#p82f87ba688)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 50.14375 143.1 \n","L 50.14375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 245.44375 143.1 \n","L 245.44375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 50.14375 143.1 \n","L 245.44375 143.1 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 50.14375 7.2 \n","L 245.44375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p82f87ba688\">\n","   <rect x=\"50.14375\" y=\"7.2\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["embed_size, num_hiddens, num_layers, dropout = 32, 32, 2, 0.1\n","batch_size, num_steps = 64, 10\n","lr, num_epochs, device = 0.005, 250, d2l.try_gpu()\n","\n","train_iter, src_vocab, tgt_vocab = d2l.load_data_nmt(batch_size, num_steps)\n","encoder = d2l.Seq2SeqEncoder(\n","    len(src_vocab), embed_size, num_hiddens, num_layers, dropout)\n","decoder = Seq2SeqAttentionDecoder(\n","    len(tgt_vocab), embed_size, num_hiddens, num_layers, dropout)\n","net = d2l.EncoderDecoder(encoder, decoder)\n","d2l.train_seq2seq(net, train_iter, lr, num_epochs, tgt_vocab, device)"],"id":"9a755137"},{"cell_type":"markdown","metadata":{"origin_pos":16,"id":"15ebd06b"},"source":["模型训练后，我们用它[**将几个英语句子翻译成法语**]并计算它们的BLEU分数。\n"],"id":"15ebd06b"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:34:40.184191Z","iopub.status.busy":"2022-07-31T02:34:40.183568Z","iopub.status.idle":"2022-07-31T02:34:40.217018Z","shell.execute_reply":"2022-07-31T02:34:40.216344Z"},"origin_pos":17,"tab":["pytorch"],"id":"f28debbb","outputId":"4d9ea71d-4346-4577-8e9e-7aad29483f7a"},"outputs":[{"name":"stdout","output_type":"stream","text":["go . => va !,  bleu 1.000\n","i lost . => j'ai perdu .,  bleu 1.000\n","he's calm . => je suis ici .,  bleu 0.000\n","i'm home . => je suis chez moi .,  bleu 1.000\n"]}],"source":["engs = ['go .', \"i lost .\", 'he\\'s calm .', 'i\\'m home .']\n","fras = ['va !', 'j\\'ai perdu .', 'il est calme .', 'je suis chez moi .']\n","for eng, fra in zip(engs, fras):\n","    translation, dec_attention_weight_seq = d2l.predict_seq2seq(\n","        net, eng, src_vocab, tgt_vocab, num_steps, device, True)\n","    print(f'{eng} => {translation}, ',\n","          f'bleu {d2l.bleu(translation, fra, k=2):.3f}')"],"id":"f28debbb"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:34:40.219959Z","iopub.status.busy":"2022-07-31T02:34:40.219602Z","iopub.status.idle":"2022-07-31T02:34:40.223758Z","shell.execute_reply":"2022-07-31T02:34:40.223090Z"},"origin_pos":19,"tab":["pytorch"],"id":"c04db862"},"outputs":[],"source":["attention_weights = torch.cat([step[0][0][0] for step in dec_attention_weight_seq], 0).reshape((\n","    1, 1, -1, num_steps))"],"id":"c04db862"},{"cell_type":"markdown","metadata":{"origin_pos":20,"id":"8faf683a"},"source":["训练结束后，下面我们通过[**可视化注意力权重**]\n","你会发现，每个查询都会在键值对上分配不同的权重，这说明\n","在每个解码步中，输入序列的不同部分被选择性地聚集在注意力池中。\n"],"id":"8faf683a"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:34:40.226781Z","iopub.status.busy":"2022-07-31T02:34:40.226425Z","iopub.status.idle":"2022-07-31T02:34:40.396752Z","shell.execute_reply":"2022-07-31T02:34:40.395920Z"},"origin_pos":22,"tab":["pytorch"],"id":"087287d6","outputId":"b5dcdc4c-3072-48b5-f79d-c71ba77ae169"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"165.99575pt\" height=\"180.65625pt\" viewBox=\"0 0 165.99575 180.65625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:34:40.351798</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 180.65625 \n","L 165.99575 180.65625 \n","L 165.99575 0 \n","L 0 0 \n","L 0 180.65625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 143.1 \n","L 124.840625 143.1 \n","L 124.840625 7.2 \n","L 34.240625 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p84e3d68c2a)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAFsAAACICAYAAACInJcYAAAB7ElEQVR4nO3dL4oVUBiH4XP1jk1BMA8YrBNcgiBuwOoSDC7KrEmQSYOTDAaDC1AwOYN6/YcM97oA8/em51nAL7x88cDZ7HeXhzVk/+50ZPf88bOR3bXWenX5c2z72tgy/xE7JHZI7JDYIbFDYofEDokdEjskdkjskNghsUNih8QOiR0SOyR2SOyQ2CGxQ9u1uxgbP5y9Htk9uXd7ZHettb58uBrbdtkhsUNih8QOiR0SOyR2SOyQ2CGxQ2KHxA6JHRI7JHZI7JDYIbFDYofEDokd2q5bd8bGNyf3R3Yvnp+N7K611unXX2PbLjskdkjskNghsUNih8QOiR0SOyR2SOyQ2CGxQ2KHxA6JHRI7JHZI7JDYIbFDYoe2m81mbPzq5YuR3W/f/47srrXW07tzTztcdkjskNghsUNih8QOiR0SOyR2SOyQ2CGxQ2KHxA6JHRI7JHZI7JDYIbFDYofEDm0Pf36MjX9++3Fk9/j45sjuWmsd3bg+tu2yQ2KHxA6JHRI7JHZI7JDYIbFDYofEDokdEjskdkjskNghsUNih8QOiR0SO7T5/eTBYWr86NHDkd39m7k/D3bvP41tu+yQ2CGxQ2KHxA6JHRI7JHZI7JDYIbFDYofEDokdEjskdkjskNghsUNih8QOiR36B68WLJFZopG7AAAAAElFTkSuQmCC\" id=\"image21ad85e647\" transform=\"scale(1 -1)translate(0 -136)\" x=\"34.240625\" y=\"-7.1\" width=\"91\" height=\"136\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m72c65f8aeb\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m72c65f8aeb\" x=\"45.565625\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(42.384375 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m72c65f8aeb\" x=\"90.865625\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 2 -->\n","      <g transform=\"translate(87.684375 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(46.477344 171.376563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"m5b85a0f72c\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"18.525\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 22.324219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"41.175\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 1 -->\n","      <g transform=\"translate(20.878125 44.974219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"63.825\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 2 -->\n","      <g transform=\"translate(20.878125 67.624219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"86.475\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 3 -->\n","      <g transform=\"translate(20.878125 90.274219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"109.125\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 4 -->\n","      <g transform=\"translate(20.878125 112.924219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m5b85a0f72c\" x=\"34.240625\" y=\"131.775\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 5 -->\n","      <g transform=\"translate(20.878125 135.574219)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798438 114.344531)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 143.1 \n","L 34.240625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 124.840625 143.1 \n","L 124.840625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 143.1 \n","L 124.840625 143.1 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 7.2 \n","L 124.840625 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 131.815625 115.92 \n","L 135.892625 115.92 \n","L 135.892625 34.38 \n","L 131.815625 34.38 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#p68433e7b92)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAQAAABRCAYAAAD1sgc6AAAAmUlEQVR4nJWRuwrDQBADL5D//1RXLsLtK20yMsh2KaSZPfya85j1871X13JBm8ZUWsZj6GpCE8HkZiMQFAMyLhoI9HHhtXK6vcM3VPucoYfZIBx01MJf6S2WMZvaQKOTEwk4mWzTaNFaS+UgKFiy2OAkeJgwZJLSoCXlsKG22VhkcCIBrJcNai00CJXJ5ulbG2B8LOOO5R/6BZQHybv/JYPcAAAAAElFTkSuQmCC\" id=\"image9cab6a598a\" transform=\"scale(1 -1)translate(0 -81)\" x=\"132\" y=\"-34\" width=\"4\" height=\"81\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_9\">\n","      <defs>\n","       <path id=\"mc72aa474a3\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mc72aa474a3\" x=\"135.892625\" y=\"83.550355\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(142.892625 87.349573)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mc72aa474a3\" x=\"135.892625\" y=\"51.031149\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(142.892625 54.830367)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 131.815625 115.92 \n","L 133.854125 115.92 \n","L 135.892625 115.92 \n","L 135.892625 34.38 \n","L 133.854125 34.38 \n","L 131.815625 34.38 \n","L 131.815625 115.92 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p84e3d68c2a\">\n","   <rect x=\"34.240625\" y=\"7.2\" width=\"90.6\" height=\"135.9\"/>\n","  </clipPath>\n","  <clipPath id=\"p68433e7b92\">\n","   <rect x=\"131.815625\" y=\"34.38\" width=\"4.077\" height=\"81.54\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 180x180 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# 加上一个包含序列结束词元\n","d2l.show_heatmaps(\n","    attention_weights[:, :, :, :len(engs[-1].split()) + 1].cpu(),\n","    xlabel='Key positions', ylabel='Query positions')"],"id":"087287d6"},{"cell_type":"markdown","metadata":{"origin_pos":24,"id":"b6cc4c16"},"source":["## 小结\n","\n","* 在预测词元时，如果不是所有输入词元都是相关的，那么具有Bahdanau注意力的循环神经网络编码器-解码器会有选择地统计输入序列的不同部分。这是通过将上下文变量视为加性注意力池化的输出来实现的。\n","* 在循环神经网络编码器-解码器中，Bahdanau注意力将上一时间步的解码器隐状态视为查询，在所有时间步的编码器隐状态同时视为键和值。\n","\n","## 练习\n","\n","1. 在实验中用LSTM替换GRU。\n","1. 修改实验以将加性注意力打分函数替换为缩放点积注意力，它如何影响训练效率？\n"],"id":"b6cc4c16"},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"1215ce85"},"source":["# 多头注意力\n",":label:`sec_multihead-attention`\n","\n","在实践中，当给定相同的查询、键和值的集合时，\n","我们希望模型可以基于相同的注意力机制学习到不同的行为，\n","然后将不同的行为作为知识组合起来，\n","捕获序列内各种范围的依赖关系\n","（例如，短距离依赖和长距离依赖关系）。\n","因此，允许注意力机制组合使用查询、键和值的不同\n","*子空间表示*（representation subspaces）可能是有益的。\n","\n","为此，与其只使用单独一个注意力汇聚，\n","我们可以用独立学习得到的$h$组不同的\n","*线性投影*（linear projections）来变换查询、键和值。\n","然后，这$h$组变换后的查询、键和值将并行地送到注意力汇聚中。\n","最后，将这$h$个注意力汇聚的输出拼接在一起，\n","并且通过另一个可以学习的线性投影进行变换，\n","以产生最终输出。\n","这种设计被称为*多头注意力*（multihead attention）\n"," :cite:`Vaswani.Shazeer.Parmar.ea.2017`。\n","对于$h$个注意力汇聚输出，每一个注意力汇聚都被称作一个*头*（head）。\n"," :numref:`fig_multi-head-attention`\n","展示了使用全连接层来实现可学习的线性变换的多头注意力。\n","\n","![多头注意力：多个头连结然后线性变换](../img/multi-head-attention.svg)\n",":label:`fig_multi-head-attention`\n","\n","## 模型\n","\n","在实现多头注意力之前，让我们用数学语言将这个模型形式化地描述出来。\n","给定查询$\\mathbf{q} \\in \\mathbb{R}^{d_q}$、\n","键$\\mathbf{k} \\in \\mathbb{R}^{d_k}$和\n","值$\\mathbf{v} \\in \\mathbb{R}^{d_v}$，\n","每个注意力头$\\mathbf{h}_i$（$i = 1, \\ldots, h$）的计算方法为：\n","\n","$$\\mathbf{h}_i = f(\\mathbf W_i^{(q)}\\mathbf q, \\mathbf W_i^{(k)}\\mathbf k,\\mathbf W_i^{(v)}\\mathbf v) \\in \\mathbb R^{p_v},$$\n","\n","其中，可学习的参数包括\n","$\\mathbf W_i^{(q)}\\in\\mathbb R^{p_q\\times d_q}$、\n","$\\mathbf W_i^{(k)}\\in\\mathbb R^{p_k\\times d_k}$和\n","$\\mathbf W_i^{(v)}\\in\\mathbb R^{p_v\\times d_v}$，\n","以及代表注意力汇聚的函数$f$。\n","$f$可以是 :numref:`sec_attention-scoring-functions`中的\n","加性注意力和缩放点积注意力。\n","多头注意力的输出需要经过另一个线性转换，\n","它对应着$h$个头连结后的结果，因此其可学习参数是\n","$\\mathbf W_o\\in\\mathbb R^{p_o\\times h p_v}$：\n","\n","$$\\mathbf W_o \\begin{bmatrix}\\mathbf h_1\\\\\\vdots\\\\\\mathbf h_h\\end{bmatrix} \\in \\mathbb{R}^{p_o}.$$\n","\n","基于这种设计，每个头都可能会关注输入的不同部分，\n","可以表示比简单加权平均值更复杂的函数。\n"],"id":"1215ce85"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:30:23.481024Z","iopub.status.busy":"2022-07-31T02:30:23.480338Z","iopub.status.idle":"2022-07-31T02:30:25.500872Z","shell.execute_reply":"2022-07-31T02:30:25.500154Z"},"origin_pos":2,"tab":["pytorch"],"id":"d3371c46"},"outputs":[],"source":["import math\n","import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"d3371c46"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"11cdef72"},"source":["## 实现\n","\n","在实现过程中，我们[**选择缩放点积注意力作为每一个注意力头**]。\n","为了避免计算代价和参数代价的大幅增长，\n","我们设定$p_q = p_k = p_v = p_o / h$。\n","值得注意的是，如果我们将查询、键和值的线性变换的输出数量设置为\n","$p_q h = p_k h = p_v h = p_o$，\n","则可以并行计算$h$个头。\n","在下面的实现中，$p_o$是通过参数`num_hiddens`指定的。\n"],"id":"11cdef72"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:30:25.505970Z","iopub.status.busy":"2022-07-31T02:30:25.505543Z","iopub.status.idle":"2022-07-31T02:30:25.513892Z","shell.execute_reply":"2022-07-31T02:30:25.513176Z"},"origin_pos":6,"tab":["pytorch"],"id":"21d14f2c"},"outputs":[],"source":["#@save\n","class MultiHeadAttention(nn.Module):\n","    \"\"\"多头注意力\"\"\"\n","    def __init__(self, key_size, query_size, value_size, num_hiddens,\n","                 num_heads, dropout, bias=False, **kwargs):\n","        super(MultiHeadAttention, self).__init__(**kwargs)\n","        self.num_heads = num_heads\n","        self.attention = d2l.DotProductAttention(dropout)\n","        self.W_q = nn.Linear(query_size, num_hiddens, bias=bias)\n","        self.W_k = nn.Linear(key_size, num_hiddens, bias=bias)\n","        self.W_v = nn.Linear(value_size, num_hiddens, bias=bias)\n","        self.W_o = nn.Linear(num_hiddens, num_hiddens, bias=bias)\n","\n","    def forward(self, queries, keys, values, valid_lens):\n","        # queries，keys，values的形状:\n","        # (batch_size，查询或者“键－值”对的个数，num_hiddens)\n","        # valid_lens　的形状:\n","        # (batch_size，)或(batch_size，查询的个数)\n","        # 经过变换后，输出的queries，keys，values　的形状:\n","        # (batch_size*num_heads，查询或者“键－值”对的个数，\n","        # num_hiddens/num_heads)\n","        queries = transpose_qkv(self.W_q(queries), self.num_heads)\n","        keys = transpose_qkv(self.W_k(keys), self.num_heads)\n","        values = transpose_qkv(self.W_v(values), self.num_heads)\n","\n","        if valid_lens is not None:\n","            # 在轴0，将第一项（标量或者矢量）复制num_heads次，\n","            # 然后如此复制第二项，然后诸如此类。\n","            valid_lens = torch.repeat_interleave(\n","                valid_lens, repeats=self.num_heads, dim=0)\n","\n","        # output的形状:(batch_size*num_heads，查询的个数，\n","        # num_hiddens/num_heads)\n","        output = self.attention(queries, keys, values, valid_lens)\n","\n","        # output_concat的形状:(batch_size，查询的个数，num_hiddens)\n","        output_concat = transpose_output(output, self.num_heads)\n","        return self.W_o(output_concat)"],"id":"21d14f2c"},{"cell_type":"markdown","metadata":{"origin_pos":8,"id":"dda437cd"},"source":["为了能够[**使多个头并行计算**]，\n","上面的`MultiHeadAttention`类将使用下面定义的两个转置函数。\n","具体来说，`transpose_output`函数反转了`transpose_qkv`函数的操作。\n"],"id":"dda437cd"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:30:25.518100Z","iopub.status.busy":"2022-07-31T02:30:25.517655Z","iopub.status.idle":"2022-07-31T02:30:25.523461Z","shell.execute_reply":"2022-07-31T02:30:25.522761Z"},"origin_pos":10,"tab":["pytorch"],"id":"500c3426"},"outputs":[],"source":["#@save\n","def transpose_qkv(X, num_heads):\n","    \"\"\"为了多注意力头的并行计算而变换形状\"\"\"\n","    # 输入X的形状:(batch_size，查询或者“键－值”对的个数，num_hiddens)\n","    # 输出X的形状:(batch_size，查询或者“键－值”对的个数，num_heads，\n","    # num_hiddens/num_heads)\n","    X = X.reshape(X.shape[0], X.shape[1], num_heads, -1)\n","\n","    # 输出X的形状:(batch_size，num_heads，查询或者“键－值”对的个数,\n","    # num_hiddens/num_heads)\n","    X = X.permute(0, 2, 1, 3)\n","\n","    # 最终输出的形状:(batch_size*num_heads,查询或者“键－值”对的个数,\n","    # num_hiddens/num_heads)\n","    return X.reshape(-1, X.shape[2], X.shape[3])\n","\n","\n","#@save\n","def transpose_output(X, num_heads):\n","    \"\"\"逆转transpose_qkv函数的操作\"\"\"\n","    X = X.reshape(-1, num_heads, X.shape[1], X.shape[2])\n","    X = X.permute(0, 2, 1, 3)\n","    return X.reshape(X.shape[0], X.shape[1], -1)"],"id":"500c3426"},{"cell_type":"markdown","metadata":{"origin_pos":12,"id":"40ab3a6f"},"source":["下面我们使用键和值相同的小例子来[**测试**]我们编写的`MultiHeadAttention`类。\n","多头注意力输出的形状是（`batch_size`，`num_queries`，`num_hiddens`）。\n"],"id":"40ab3a6f"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:30:25.527571Z","iopub.status.busy":"2022-07-31T02:30:25.527066Z","iopub.status.idle":"2022-07-31T02:30:25.536359Z","shell.execute_reply":"2022-07-31T02:30:25.535758Z"},"origin_pos":14,"tab":["pytorch"],"id":"9175c93a","outputId":"837ebc72-3d70-447b-8caf-1f7bcab5bdb5"},"outputs":[{"data":{"text/plain":["MultiHeadAttention(\n","  (attention): DotProductAttention(\n","    (dropout): Dropout(p=0.5, inplace=False)\n","  )\n","  (W_q): Linear(in_features=100, out_features=100, bias=False)\n","  (W_k): Linear(in_features=100, out_features=100, bias=False)\n","  (W_v): Linear(in_features=100, out_features=100, bias=False)\n","  (W_o): Linear(in_features=100, out_features=100, bias=False)\n",")"]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["num_hiddens, num_heads = 100, 5\n","attention = MultiHeadAttention(num_hiddens, num_hiddens, num_hiddens,\n","                               num_hiddens, num_heads, 0.5)\n","attention.eval()"],"id":"9175c93a"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:30:25.540655Z","iopub.status.busy":"2022-07-31T02:30:25.540081Z","iopub.status.idle":"2022-07-31T02:30:25.550109Z","shell.execute_reply":"2022-07-31T02:30:25.549437Z"},"origin_pos":16,"tab":["pytorch"],"id":"d34ab74f","outputId":"b0566616-4cb8-41fb-9bc5-6649176e0b8f"},"outputs":[{"data":{"text/plain":["torch.Size([2, 4, 100])"]},"execution_count":5,"metadata":{},"output_type":"execute_result"}],"source":["batch_size, num_queries = 2, 4\n","num_kvpairs, valid_lens =  6, torch.tensor([3, 2])\n","X = torch.ones((batch_size, num_queries, num_hiddens))\n","Y = torch.ones((batch_size, num_kvpairs, num_hiddens))\n","attention(X, Y, Y, valid_lens).shape"],"id":"d34ab74f"},{"cell_type":"markdown","metadata":{"origin_pos":18,"id":"3d8f45a5"},"source":["## 小结\n","\n","* 多头注意力融合了来自于多个注意力汇聚的不同知识，这些知识的不同来源于相同的查询、键和值的不同的子空间表示。\n","* 基于适当的张量操作，可以实现多头注意力的并行计算。\n","\n","## 练习\n","\n","1. 分别可视化这个实验中的多个头的注意力权重。\n","1. 假设我们有一个完成训练的基于多头注意力的模型，现在希望修剪最不重要的注意力头以提高预测速度。如何设计实验来衡量注意力头的重要性呢？\n"],"id":"3d8f45a5"},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"85232728"},"source":["# 自注意力和位置编码\n",":label:`sec_self-attention-and-positional-encoding`\n","\n","在深度学习中，我们经常使用卷积神经网络（CNN）或循环神经网络（RNN）对序列进行编码。\n","想象一下，有了注意力机制之后，我们将词元序列输入注意力汇聚中，\n","以便同一组词元同时充当查询、键和值。\n","具体来说，每个查询都会关注所有的键－值对并生成一个注意力输出。\n","由于查询、键和值来自同一组输入，因此被称为\n","*自注意力*（self-attention）\n"," :cite:`Lin.Feng.Santos.ea.2017,Vaswani.Shazeer.Parmar.ea.2017`，\n","也被称为*内部注意力*（intra-attention） :cite:`Cheng.Dong.Lapata.2016,Parikh.Tackstrom.Das.ea.2016,Paulus.Xiong.Socher.2017`。\n","在本节中，我们将使用自注意力进行序列编码，以及如何使用序列的顺序作为补充信息。\n"],"id":"85232728"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:05.274362Z","iopub.status.busy":"2022-07-31T02:39:05.273818Z","iopub.status.idle":"2022-07-31T02:39:07.148436Z","shell.execute_reply":"2022-07-31T02:39:07.147504Z"},"origin_pos":2,"tab":["pytorch"],"id":"d986e91e"},"outputs":[],"source":["import math\n","import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"d986e91e"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"0794f484"},"source":["## [**自注意力**]\n","\n","给定一个由词元组成的输入序列$\\mathbf{x}_1, \\ldots, \\mathbf{x}_n$，\n","其中任意$\\mathbf{x}_i \\in \\mathbb{R}^d$（$1 \\leq i \\leq n$）。\n","该序列的自注意力输出为一个长度相同的序列\n","$\\mathbf{y}_1, \\ldots, \\mathbf{y}_n$，其中：\n","\n","$$\\mathbf{y}_i = f(\\mathbf{x}_i, (\\mathbf{x}_1, \\mathbf{x}_1), \\ldots, (\\mathbf{x}_n, \\mathbf{x}_n)) \\in \\mathbb{R}^d$$\n","\n","根据 :eqref:`eq_attn-pooling`中定义的注意力汇聚函数$f$。\n","下面的代码片段是基于多头注意力对一个张量完成自注意力的计算，\n","张量的形状为（批量大小，时间步的数目或词元序列的长度，$d$）。\n","输出与输入的张量形状相同。\n"],"id":"0794f484"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.152165Z","iopub.status.busy":"2022-07-31T02:39:07.151757Z","iopub.status.idle":"2022-07-31T02:39:07.160931Z","shell.execute_reply":"2022-07-31T02:39:07.160018Z"},"origin_pos":6,"tab":["pytorch"],"id":"a7215efd","outputId":"88690c4d-b9b7-4755-ac4e-8f5ce5822d63"},"outputs":[{"data":{"text/plain":["MultiHeadAttention(\n","  (attention): DotProductAttention(\n","    (dropout): Dropout(p=0.5, inplace=False)\n","  )\n","  (W_q): Linear(in_features=100, out_features=100, bias=False)\n","  (W_k): Linear(in_features=100, out_features=100, bias=False)\n","  (W_v): Linear(in_features=100, out_features=100, bias=False)\n","  (W_o): Linear(in_features=100, out_features=100, bias=False)\n",")"]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["num_hiddens, num_heads = 100, 5\n","attention = d2l.MultiHeadAttention(num_hiddens, num_hiddens, num_hiddens,\n","                                   num_hiddens, num_heads, 0.5)\n","attention.eval()"],"id":"a7215efd"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.163900Z","iopub.status.busy":"2022-07-31T02:39:07.163521Z","iopub.status.idle":"2022-07-31T02:39:07.174104Z","shell.execute_reply":"2022-07-31T02:39:07.173243Z"},"origin_pos":8,"tab":["pytorch"],"id":"595cbe3a","outputId":"b56e763c-f460-4414-8712-dd1f5762f64d"},"outputs":[{"data":{"text/plain":["torch.Size([2, 4, 100])"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["batch_size, num_queries, valid_lens = 2, 4, torch.tensor([3, 2])\n","X = torch.ones((batch_size, num_queries, num_hiddens))\n","attention(X, X, X, valid_lens).shape"],"id":"595cbe3a"},{"cell_type":"markdown","metadata":{"origin_pos":10,"id":"e193d3c1"},"source":["## 比较卷积神经网络、循环神经网络和自注意力\n",":label:`subsec_cnn-rnn-self-attention`\n","\n","让我们比较下面几个架构，目标都是将由$n$个词元组成的序列映射到另一个长度相等的序列，其中的每个输入词元或输出词元都由$d$维向量表示。具体来说，我们将比较的是卷积神经网络、循环神经网络和自注意力这几个架构的计算复杂性、顺序操作和最大路径长度。请注意，顺序操作会妨碍并行计算，而任意的序列位置组合之间的路径越短，则能更轻松地学习序列中的远距离依赖关系 :cite:`Hochreiter.Bengio.Frasconi.ea.2001`。\n","\n","![比较卷积神经网络（填充词元被忽略）、循环神经网络和自注意力三种架构](../img/cnn-rnn-self-attention.svg)\n",":label:`fig_cnn-rnn-self-attention`\n","\n","考虑一个卷积核大小为$k$的卷积层。\n","我们将在后面的章节中提供关于使用卷积神经网络处理序列的更多详细信息。\n","目前，我们只需要知道，由于序列长度是$n$，输入和输出的通道数量都是$d$，\n","所以卷积层的计算复杂度为$\\mathcal{O}(knd^2)$。\n","如 :numref:`fig_cnn-rnn-self-attention`所示，\n","卷积神经网络是分层的，因此为有$\\mathcal{O}(1)$个顺序操作，\n","最大路径长度为$\\mathcal{O}(n/k)$。\n","例如，$\\mathbf{x}_1$和$\\mathbf{x}_5$处于\n"," :numref:`fig_cnn-rnn-self-attention`中卷积核大小为3的双层卷积神经网络的感受野内。\n","\n","当更新循环神经网络的隐状态时，\n","$d \\times d$权重矩阵和$d$维隐状态的乘法计算复杂度为$\\mathcal{O}(d^2)$。\n","由于序列长度为$n$，因此循环神经网络层的计算复杂度为$\\mathcal{O}(nd^2)$。\n","根据 :numref:`fig_cnn-rnn-self-attention`，\n","有$\\mathcal{O}(n)$个顺序操作无法并行化，最大路径长度也是$\\mathcal{O}(n)$。\n","\n","在自注意力中，查询、键和值都是$n \\times d$矩阵。\n","考虑 :eqref:`eq_softmax_QK_V`中缩放的”点－积“注意力，\n","其中$n \\times d$矩阵乘以$d \\times n$矩阵。\n","之后输出的$n \\times n$矩阵乘以$n \\times d$矩阵。\n","因此，自注意力具有$\\mathcal{O}(n^2d)$计算复杂性。\n","正如我们在 :numref:`fig_cnn-rnn-self-attention`中看到的那样，\n","每个词元都通过自注意力直接连接到任何其他词元。\n","因此，有$\\mathcal{O}(1)$个顺序操作可以并行计算，\n","最大路径长度也是$\\mathcal{O}(1)$。\n","\n","总而言之，卷积神经网络和自注意力都拥有并行计算的优势，\n","而且自注意力的最大路径长度最短。\n","但是因为其计算复杂度是关于序列长度的二次方，所以在很长的序列中计算会非常慢。\n","\n","## [**位置编码**]\n",":label:`subsec_positional-encoding`\n","\n","在处理词元序列时，循环神经网络是逐个的重复地处理词元的，\n","而自注意力则因为并行计算而放弃了顺序操作。\n","为了使用序列的顺序信息，我们通过在输入表示中添加\n","*位置编码*（positional encoding）来注入绝对的或相对的位置信息。\n","位置编码可以通过学习得到也可以直接固定得到。\n","接下来，我们描述的是基于正弦函数和余弦函数的固定位置编码\n"," :cite:`Vaswani.Shazeer.Parmar.ea.2017`。\n","\n","假设输入表示$\\mathbf{X} \\in \\mathbb{R}^{n \\times d}$\n","包含一个序列中$n$个词元的$d$维嵌入表示。\n","位置编码使用相同形状的位置嵌入矩阵\n","$\\mathbf{P} \\in \\mathbb{R}^{n \\times d}$输出$\\mathbf{X} + \\mathbf{P}$，\n","矩阵第$i$行、第$2j$列和$2j+1$列上的元素为：\n","\n","$$\\begin{aligned} p_{i, 2j} &= \\sin\\left(\\frac{i}{10000^{2j/d}}\\right),\\\\p_{i, 2j+1} &= \\cos\\left(\\frac{i}{10000^{2j/d}}\\right).\\end{aligned}$$\n",":eqlabel:`eq_positional-encoding-def`\n","\n","乍一看，这种基于三角函数的设计看起来很奇怪。\n","在解释这个设计之前，让我们先在下面的`PositionalEncoding`类中实现它。\n"],"id":"e193d3c1"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.177223Z","iopub.status.busy":"2022-07-31T02:39:07.176844Z","iopub.status.idle":"2022-07-31T02:39:07.184097Z","shell.execute_reply":"2022-07-31T02:39:07.183266Z"},"origin_pos":12,"tab":["pytorch"],"id":"077e6e06"},"outputs":[],"source":["#@save\n","class PositionalEncoding(nn.Module):\n","    \"\"\"位置编码\"\"\"\n","    def __init__(self, num_hiddens, dropout, max_len=1000):\n","        super(PositionalEncoding, self).__init__()\n","        self.dropout = nn.Dropout(dropout)\n","        # 创建一个足够长的P\n","        self.P = torch.zeros((1, max_len, num_hiddens))\n","        X = torch.arange(max_len, dtype=torch.float32).reshape(\n","            -1, 1) / torch.pow(10000, torch.arange(\n","            0, num_hiddens, 2, dtype=torch.float32) / num_hiddens)\n","        self.P[:, :, 0::2] = torch.sin(X)\n","        self.P[:, :, 1::2] = torch.cos(X)\n","\n","    def forward(self, X):\n","        X = X + self.P[:, :X.shape[1], :].to(X.device)\n","        return self.dropout(X)"],"id":"077e6e06"},{"cell_type":"markdown","metadata":{"origin_pos":14,"id":"4c89e013"},"source":["在位置嵌入矩阵$\\mathbf{P}$中，\n","[**行代表词元在序列中的位置，列代表位置编码的不同维度**]。\n","在下面的例子中，我们可以看到位置嵌入矩阵的第$6$列和第$7$列的频率高于第$8$列和第$9$列。\n","第$6$列和第$7$列之间的偏移量（第$8$列和第$9$列相同）是由于正弦函数和余弦函数的交替。\n"],"id":"4c89e013"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.186955Z","iopub.status.busy":"2022-07-31T02:39:07.186595Z","iopub.status.idle":"2022-07-31T02:39:07.406896Z","shell.execute_reply":"2022-07-31T02:39:07.406022Z"},"origin_pos":16,"tab":["pytorch"],"id":"5e16eaff","outputId":"b0fa19e5-54bc-4009-efa1-34f66382205a"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"380.482812pt\" height=\"180.65625pt\" viewBox=\"0 0 380.482812 180.65625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:39:07.353546</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M -0 180.65625 \n","L 380.482812 180.65625 \n","L 380.482812 0 \n","L -0 0 \n","L -0 180.65625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 38.482813 143.1 \n","L 373.282813 143.1 \n","L 373.282813 7.2 \n","L 38.482813 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 53.700994 143.1 \n","L 53.700994 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"m38fb30ad79\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"53.700994\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(50.519744 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 105.288051 143.1 \n","L 105.288051 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"105.288051\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 10 -->\n","      <g transform=\"translate(98.925551 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 156.875108 143.1 \n","L 156.875108 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"156.875108\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 20 -->\n","      <g transform=\"translate(150.512608 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 208.462165 143.1 \n","L 208.462165 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"208.462165\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 30 -->\n","      <g transform=\"translate(202.099665 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 260.049222 143.1 \n","L 260.049222 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"260.049222\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 40 -->\n","      <g transform=\"translate(253.686722 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 311.636279 143.1 \n","L 311.636279 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"311.636279\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 50 -->\n","      <g transform=\"translate(305.273779 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_7\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 363.223336 143.1 \n","L 363.223336 7.2 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#m38fb30ad79\" x=\"363.223336\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 60 -->\n","      <g transform=\"translate(356.860836 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-36\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_8\">\n","     <!-- Row (position) -->\n","     <g transform=\"translate(170.189844 171.376563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-52\" d=\"M 2841 2188 \n","Q 3044 2119 3236 1894 \n","Q 3428 1669 3622 1275 \n","L 4263 0 \n","L 3584 0 \n","L 2988 1197 \n","Q 2756 1666 2539 1819 \n","Q 2322 1972 1947 1972 \n","L 1259 1972 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","L 2053 4666 \n","Q 2853 4666 3247 4331 \n","Q 3641 3997 3641 3322 \n","Q 3641 2881 3436 2590 \n","Q 3231 2300 2841 2188 \n","z\n","M 1259 4147 \n","L 1259 2491 \n","L 2053 2491 \n","Q 2509 2491 2742 2702 \n","Q 2975 2913 2975 3322 \n","Q 2975 3731 2742 3939 \n","Q 2509 4147 2053 4147 \n","L 1259 4147 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-77\" d=\"M 269 3500 \n","L 844 3500 \n","L 1563 769 \n","L 2278 3500 \n","L 2956 3500 \n","L 3675 769 \n","L 4391 3500 \n","L 4966 3500 \n","L 4050 0 \n","L 3372 0 \n","L 2619 2869 \n","L 1863 0 \n","L 1184 0 \n","L 269 3500 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \n","Q 1566 4138 1362 3434 \n","Q 1159 2731 1159 2009 \n","Q 1159 1288 1364 580 \n","Q 1569 -128 1984 -844 \n","L 1484 -844 \n","Q 1016 -109 783 600 \n","Q 550 1309 550 2009 \n","Q 550 2706 781 3412 \n","Q 1013 4119 1484 4856 \n","L 1984 4856 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \n","L 1013 4856 \n","Q 1481 4119 1714 3412 \n","Q 1947 2706 1947 2009 \n","Q 1947 1309 1714 600 \n","Q 1481 -109 1013 -844 \n","L 513 -844 \n","Q 928 -128 1133 580 \n","Q 1338 1288 1338 2009 \n","Q 1338 2731 1133 3434 \n","Q 928 4138 513 4856 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-52\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"64.982422\"/>\n","      <use xlink:href=\"#DejaVuSans-77\" x=\"126.164062\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"207.951172\"/>\n","      <use xlink:href=\"#DejaVuSans-28\" x=\"239.738281\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"278.751953\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"342.228516\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"403.410156\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"455.509766\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"483.292969\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"522.501953\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"550.285156\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"611.466797\"/>\n","      <use xlink:href=\"#DejaVuSans-29\" x=\"674.845703\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_15\">\n","      <path d=\"M 38.482813 136.922727 \n","L 373.282813 136.922727 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_16\">\n","      <defs>\n","       <path id=\"m967493a4cd\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m967493a4cd\" x=\"38.482813\" y=\"136.922727\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- −1.0 -->\n","      <g transform=\"translate(7.2 140.721946)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n","L 4684 2272 \n","L 4684 1741 \n","L 678 1741 \n","L 678 2272 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"179.199219\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_17\">\n","      <path d=\"M 38.482813 106.036364 \n","L 373.282813 106.036364 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#m967493a4cd\" x=\"38.482813\" y=\"106.036364\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- −0.5 -->\n","      <g transform=\"translate(7.2 109.835582)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"83.789062\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"179.199219\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_19\">\n","      <path d=\"M 38.482813 75.15 \n","L 373.282813 75.15 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#m967493a4cd\" x=\"38.482813\" y=\"75.15\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(15.579688 78.949219)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_21\">\n","      <path d=\"M 38.482813 44.263636 \n","L 373.282813 44.263636 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#m967493a4cd\" x=\"38.482813\" y=\"44.263636\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0.5 -->\n","      <g transform=\"translate(15.579688 48.062855)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_23\">\n","      <path d=\"M 38.482813 13.377273 \n","L 373.282813 13.377273 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#m967493a4cd\" x=\"38.482813\" y=\"13.377273\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 1.0 -->\n","      <g transform=\"translate(15.579688 17.176491)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_25\">\n","    <path d=\"M 53.700994 75.15 \n","L 58.8597 64.222887 \n","L 64.018406 53.640411 \n","L 69.177111 43.736334 \n","L 74.335817 34.823035 \n","L 79.494523 27.181626 \n","L 84.653229 21.053116 \n","L 89.811934 16.630798 \n","L 94.97064 14.05415 \n","L 100.129346 13.404434 \n","L 105.288051 14.702142 \n","L 110.446757 17.906352 \n","L 115.605463 22.916001 \n","L 120.764168 29.57308 \n","L 125.922874 37.667644 \n","L 131.08158 46.944371 \n","L 136.240286 57.11069 \n","L 141.398991 67.845975 \n","L 146.557697 78.81161 \n","L 151.716403 89.661775 \n","L 156.875108 100.05423 \n","L 162.033814 109.661231 \n","L 167.19252 118.179753 \n","L 172.351225 125.341136 \n","L 177.509931 130.919532 \n","L 182.668637 134.738964 \n","L 187.827343 136.678994 \n","L 192.986048 136.678427 \n","L 198.144754 134.737281 \n","L 203.30346 130.916781 \n","L 208.462165 125.337425 \n","L 213.620871 118.175187 \n","L 218.779577 109.655955 \n","L 223.938282 100.048393 \n","L 229.096988 89.655575 \n","L 234.255694 78.805258 \n","L 239.4144 67.839656 \n","L 244.573105 57.104589 \n","L 249.731811 46.938698 \n","L 254.890517 37.662574 \n","L 260.049222 29.568787 \n","L 265.207928 22.912588 \n","L 270.366634 17.903955 \n","L 275.525339 14.700831 \n","L 280.684045 13.404247 \n","L 285.842751 14.055089 \n","L 291.001457 16.632831 \n","L 296.160162 21.056179 \n","L 301.318868 27.185658 \n","L 306.477574 34.827873 \n","L 311.636279 43.741832 \n","L 316.794985 53.646389 \n","L 321.953691 64.229157 \n","L 327.112396 75.156364 \n","L 332.271102 86.08337 \n","L 337.429808 96.665543 \n","L 342.588514 106.569177 \n","L 347.747219 115.48181 \n","L 352.905925 123.122402 \n","L 358.064631 129.249966 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"line2d_26\">\n","    <path d=\"M 53.700994 13.377273 \n","L 58.8597 14.351415 \n","L 64.018406 17.243112 \n","L 69.177111 21.961171 \n","L 74.335817 28.356777 \n","L 79.494523 36.228223 \n","L 84.653229 45.327242 \n","L 89.811934 55.366859 \n","L 94.97064 66.030417 \n","L 100.129346 76.981611 \n","L 105.288051 87.875035 \n","L 110.446757 98.367119 \n","L 115.605463 108.126952 \n","L 120.764168 116.846695 \n","L 125.922874 124.251351 \n","L 131.08158 130.107369 \n","L 136.240286 134.230057 \n","L 141.398991 136.489392 \n","L 146.557697 136.81411 \n","L 151.716403 135.193971 \n","L 156.875108 131.680073 \n","L 162.033814 126.38324 \n","L 167.19252 119.470538 \n","L 172.351225 111.159995 \n","L 177.509931 101.713683 \n","L 182.668637 91.429594 \n","L 187.827343 80.632052 \n","L 192.986048 69.66161 \n","L 198.144754 58.864239 \n","L 203.30346 48.580543 \n","L 208.462165 39.134835 \n","L 213.620871 30.825029 \n","L 218.779577 23.913207 \n","L 223.938282 18.617357 \n","L 229.096988 15.104534 \n","L 234.255694 13.485514 \n","L 239.4144 13.811359 \n","L 244.573105 16.071806 \n","L 249.731811 20.195543 \n","L 254.890517 26.052518 \n","L 260.049222 33.458003 \n","L 265.207928 42.178453 \n","L 270.366634 51.938792 \n","L 275.525339 62.431199 \n","L 280.684045 73.324751 \n","L 285.842751 84.27587 \n","L 291.001457 94.939163 \n","L 296.160162 104.978317 \n","L 301.318868 114.076744 \n","L 306.477574 121.947395 \n","L 311.636279 128.342073 \n","L 316.794985 133.059108 \n","L 321.953691 135.949712 \n","L 327.112396 136.922727 \n","L 332.271102 135.947462 \n","L 337.429808 133.054675 \n","L 342.588514 128.335571 \n","L 347.747219 121.939044 \n","L 352.905925 114.066818 \n","L 358.064631 104.96717 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"line2d_27\">\n","    <path d=\"M 53.700994 75.15 \n","L 58.8597 68.983017 \n","L 64.018406 62.877654 \n","L 69.177111 56.89491 \n","L 74.335817 51.094566 \n","L 79.494523 45.534576 \n","L 84.653229 40.270494 \n","L 89.811934 35.354918 \n","L 94.97064 30.836958 \n","L 100.129346 26.761763 \n","L 105.288051 23.170044 \n","L 110.446757 20.097689 \n","L 115.605463 17.575404 \n","L 120.764168 15.628382 \n","L 125.922874 14.276083 \n","L 131.08158 13.532014 \n","L 136.240286 13.403613 \n","L 141.398991 13.892159 \n","L 146.557697 14.992776 \n","L 151.716403 16.694463 \n","L 156.875108 18.980219 \n","L 162.033814 21.8272 \n","L 167.19252 25.206975 \n","L 172.351225 29.085753 \n","L 177.509931 33.424803 \n","L 182.668637 38.180745 \n","L 187.827343 43.30607 \n","L 192.986048 48.749581 \n","L 198.144754 54.456865 \n","L 203.30346 60.370922 \n","L 208.462165 66.432633 \n","L 213.620871 72.581443 \n","L 218.779577 78.755933 \n","L 223.938282 84.894379 \n","L 229.096988 90.935477 \n","L 234.255694 96.818837 \n","L 239.4144 102.485689 \n","L 244.573105 107.879426 \n","L 249.731811 112.946127 \n","L 254.890517 117.635197 \n","L 260.049222 121.899754 \n","L 265.207928 125.697206 \n","L 270.366634 128.989605 \n","L 275.525339 131.744073 \n","L 280.684045 133.933057 \n","L 285.842751 135.534702 \n","L 291.001457 136.533001 \n","L 296.160162 136.917985 \n","L 301.318868 136.685802 \n","L 306.477574 135.838775 \n","L 311.636279 134.385369 \n","L 316.794985 132.340102 \n","L 321.953691 129.723409 \n","L 327.112396 126.561424 \n","L 332.271102 122.885767 \n","L 337.429808 118.733148 \n","L 342.588514 114.145067 \n","L 347.747219 109.167358 \n","L 352.905925 103.849734 \n","L 358.064631 98.245375 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"line2d_28\">\n","    <path d=\"M 53.700994 13.377273 \n","L 58.8597 13.685878 \n","L 64.018406 14.608613 \n","L 69.177111 16.136258 \n","L 74.335817 18.253551 \n","L 79.494523 20.939332 \n","L 84.653229 24.166768 \n","L 89.811934 27.903611 \n","L 94.97064 32.112526 \n","L 100.129346 36.751456 \n","L 105.288051 41.774051 \n","L 110.446757 47.130131 \n","L 115.605463 52.766176 \n","L 120.764168 58.625865 \n","L 125.922874 64.650665 \n","L 131.08158 70.78037 \n","L 136.240286 76.953736 \n","L 141.398991 83.109079 \n","L 146.557697 89.18489 \n","L 151.716403 95.120477 \n","L 156.875108 100.856526 \n","L 162.033814 106.335717 \n","L 167.19252 111.503321 \n","L 172.351225 116.307684 \n","L 177.509931 120.700826 \n","L 182.668637 124.638824 \n","L 187.827343 128.082353 \n","L 192.986048 130.997003 \n","L 198.144754 133.353645 \n","L 203.30346 135.128734 \n","L 208.462165 136.304537 \n","L 213.620871 136.869302 \n","L 218.779577 136.817391 \n","L 223.938282 136.149321 \n","L 229.096988 134.871761 \n","L 234.255694 132.997483 \n","L 239.4144 130.545214 \n","L 244.573105 127.53945 \n","L 249.731811 124.010236 \n","L 254.890517 119.992814 \n","L 260.049222 115.527348 \n","L 265.207928 110.658448 \n","L 270.366634 105.434758 \n","L 275.525339 99.908448 \n","L 280.684045 94.134784 \n","L 285.842751 88.171432 \n","L 291.001457 82.077973 \n","L 296.160162 75.915293 \n","L 301.318868 69.744938 \n","L 306.477574 63.628616 \n","L 311.636279 57.627412 \n","L 316.794985 51.801289 \n","L 321.953691 46.208458 \n","L 327.112396 40.904774 \n","L 332.271102 35.943284 \n","L 337.429808 31.373535 \n","L 342.588514 27.241185 \n","L 347.747219 23.587521 \n","L 352.905925 20.449038 \n","L 358.064631 17.857124 \n","\" clip-path=\"url(#p0b3da2accb)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff0000; stroke-width: 1.5\"/>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 38.482813 143.1 \n","L 38.482813 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 373.282813 143.1 \n","L 373.282813 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 38.482813 143.1 \n","L 373.282812 143.1 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 38.482813 7.2 \n","L 373.282812 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"legend_1\">\n","    <g id=\"patch_7\">\n","     <path d=\"M 45.482813 138.1 \n","L 102.903125 138.1 \n","Q 104.903125 138.1 104.903125 136.1 \n","L 104.903125 78.3875 \n","Q 104.903125 76.3875 102.903125 76.3875 \n","L 45.482813 76.3875 \n","Q 43.482813 76.3875 43.482813 78.3875 \n","L 43.482813 136.1 \n","Q 43.482813 138.1 45.482813 138.1 \n","z\n","\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n","    </g>\n","    <g id=\"line2d_29\">\n","     <path d=\"M 47.482813 84.485937 \n","L 57.482813 84.485937 \n","L 67.482812 84.485937 \n","\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","    </g>\n","    <g id=\"text_14\">\n","     <!-- Col 6 -->\n","     <g transform=\"translate(75.482812 87.985937)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-43\" d=\"M 4122 4306 \n","L 4122 3641 \n","Q 3803 3938 3442 4084 \n","Q 3081 4231 2675 4231 \n","Q 1875 4231 1450 3742 \n","Q 1025 3253 1025 2328 \n","Q 1025 1406 1450 917 \n","Q 1875 428 2675 428 \n","Q 3081 428 3442 575 \n","Q 3803 722 4122 1019 \n","L 4122 359 \n","Q 3791 134 3420 21 \n","Q 3050 -91 2638 -91 \n","Q 1578 -91 968 557 \n","Q 359 1206 359 2328 \n","Q 359 3453 968 4101 \n","Q 1578 4750 2638 4750 \n","Q 3056 4750 3426 4639 \n","Q 3797 4528 4122 4306 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n","L 1178 4863 \n","L 1178 0 \n","L 603 0 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-43\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"69.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-6c\" x=\"131.005859\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"158.789062\"/>\n","      <use xlink:href=\"#DejaVuSans-36\" x=\"190.576172\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_30\">\n","     <path d=\"M 47.482813 99.164062 \n","L 57.482813 99.164062 \n","L 67.482812 99.164062 \n","\" style=\"fill: none; stroke-dasharray: 5.55,2.4; stroke-dashoffset: 0; stroke: #bf00bf; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_15\">\n","     <!-- Col 7 -->\n","     <g transform=\"translate(75.482812 102.664062)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-37\" d=\"M 525 4666 \n","L 3525 4666 \n","L 3525 4397 \n","L 1831 0 \n","L 1172 0 \n","L 2766 4134 \n","L 525 4134 \n","L 525 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-43\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"69.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-6c\" x=\"131.005859\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"158.789062\"/>\n","      <use xlink:href=\"#DejaVuSans-37\" x=\"190.576172\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_31\">\n","     <path d=\"M 47.482813 113.842187 \n","L 57.482813 113.842187 \n","L 67.482812 113.842187 \n","\" style=\"fill: none; stroke-dasharray: 9.6,2.4,1.5,2.4; stroke-dashoffset: 0; stroke: #008000; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_16\">\n","     <!-- Col 8 -->\n","     <g transform=\"translate(75.482812 117.342187)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n","Q 1584 2216 1326 1975 \n","Q 1069 1734 1069 1313 \n","Q 1069 891 1326 650 \n","Q 1584 409 2034 409 \n","Q 2484 409 2743 651 \n","Q 3003 894 3003 1313 \n","Q 3003 1734 2745 1975 \n","Q 2488 2216 2034 2216 \n","z\n","M 1403 2484 \n","Q 997 2584 770 2862 \n","Q 544 3141 544 3541 \n","Q 544 4100 942 4425 \n","Q 1341 4750 2034 4750 \n","Q 2731 4750 3128 4425 \n","Q 3525 4100 3525 3541 \n","Q 3525 3141 3298 2862 \n","Q 3072 2584 2669 2484 \n","Q 3125 2378 3379 2068 \n","Q 3634 1759 3634 1313 \n","Q 3634 634 3220 271 \n","Q 2806 -91 2034 -91 \n","Q 1263 -91 848 271 \n","Q 434 634 434 1313 \n","Q 434 1759 690 2068 \n","Q 947 2378 1403 2484 \n","z\n","M 1172 3481 \n","Q 1172 3119 1398 2916 \n","Q 1625 2713 2034 2713 \n","Q 2441 2713 2670 2916 \n","Q 2900 3119 2900 3481 \n","Q 2900 3844 2670 4047 \n","Q 2441 4250 2034 4250 \n","Q 1625 4250 1398 4047 \n","Q 1172 3844 1172 3481 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-43\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"69.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-6c\" x=\"131.005859\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"158.789062\"/>\n","      <use xlink:href=\"#DejaVuSans-38\" x=\"190.576172\"/>\n","     </g>\n","    </g>\n","    <g id=\"line2d_32\">\n","     <path d=\"M 47.482813 128.520312 \n","L 57.482813 128.520312 \n","L 67.482812 128.520312 \n","\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff0000; stroke-width: 1.5\"/>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Col 9 -->\n","     <g transform=\"translate(75.482812 132.020312)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-39\" d=\"M 703 97 \n","L 703 672 \n","Q 941 559 1184 500 \n","Q 1428 441 1663 441 \n","Q 2288 441 2617 861 \n","Q 2947 1281 2994 2138 \n","Q 2813 1869 2534 1725 \n","Q 2256 1581 1919 1581 \n","Q 1219 1581 811 2004 \n","Q 403 2428 403 3163 \n","Q 403 3881 828 4315 \n","Q 1253 4750 1959 4750 \n","Q 2769 4750 3195 4129 \n","Q 3622 3509 3622 2328 \n","Q 3622 1225 3098 567 \n","Q 2575 -91 1691 -91 \n","Q 1453 -91 1209 -44 \n","Q 966 3 703 97 \n","z\n","M 1959 2075 \n","Q 2384 2075 2632 2365 \n","Q 2881 2656 2881 3163 \n","Q 2881 3666 2632 3958 \n","Q 2384 4250 1959 4250 \n","Q 1534 4250 1286 3958 \n","Q 1038 3666 1038 3163 \n","Q 1038 2656 1286 2365 \n","Q 1534 2075 1959 2075 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-43\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"69.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-6c\" x=\"131.005859\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"158.789062\"/>\n","      <use xlink:href=\"#DejaVuSans-39\" x=\"190.576172\"/>\n","     </g>\n","    </g>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p0b3da2accb\">\n","   <rect x=\"38.482813\" y=\"7.2\" width=\"334.8\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 432x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["encoding_dim, num_steps = 32, 60\n","pos_encoding = PositionalEncoding(encoding_dim, 0)\n","pos_encoding.eval()\n","X = pos_encoding(torch.zeros((1, num_steps, encoding_dim)))\n","P = pos_encoding.P[:, :X.shape[1], :]\n","d2l.plot(torch.arange(num_steps), P[0, :, 6:10].T, xlabel='Row (position)',\n","         figsize=(6, 2.5), legend=[\"Col %d\" % d for d in torch.arange(6, 10)])"],"id":"5e16eaff"},{"cell_type":"markdown","metadata":{"origin_pos":18,"id":"68bc10bb"},"source":["### 绝对位置信息\n","\n","为了明白沿着编码维度单调降低的频率与绝对位置信息的关系，\n","让我们打印出$0, 1, \\ldots, 7$的[**二进制表示**]形式。\n","正如我们所看到的，每个数字、每两个数字和每四个数字上的比特值\n","在第一个最低位、第二个最低位和第三个最低位上分别交替。\n"],"id":"68bc10bb"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.410346Z","iopub.status.busy":"2022-07-31T02:39:07.409684Z","iopub.status.idle":"2022-07-31T02:39:07.414995Z","shell.execute_reply":"2022-07-31T02:39:07.414122Z"},"origin_pos":19,"tab":["pytorch"],"id":"d5423af4","outputId":"4a394ec4-ac3e-4fa7-b62a-dfc9d96cbf41"},"outputs":[{"name":"stdout","output_type":"stream","text":["0的二进制是：000\n","1的二进制是：001\n","2的二进制是：010\n","3的二进制是：011\n","4的二进制是：100\n","5的二进制是：101\n","6的二进制是：110\n","7的二进制是：111\n"]}],"source":["for i in range(8):\n","    print(f'{i}的二进制是：{i:>03b}')"],"id":"d5423af4"},{"cell_type":"markdown","metadata":{"origin_pos":20,"id":"7efb56d2"},"source":["在二进制表示中，较高比特位的交替频率低于较低比特位，\n","与下面的热图所示相似，只是位置编码通过使用三角函数[**在编码维度上降低频率**]。\n","由于输出是浮点数，因此此类连续表示比二进制表示法更节省空间。\n"],"id":"7efb56d2"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T02:39:07.418095Z","iopub.status.busy":"2022-07-31T02:39:07.417491Z","iopub.status.idle":"2022-07-31T02:39:07.599370Z","shell.execute_reply":"2022-07-31T02:39:07.598385Z"},"origin_pos":22,"tab":["pytorch"],"id":"a5684c9c","outputId":"65779bb6-1193-47c5-f2f8-a85bb6fd7b9d"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"211.342137pt\" height=\"264.183469pt\" viewBox=\"0 0 211.342137 264.183469\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T02:39:07.547410</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 264.183469 \n","L 211.342137 264.183469 \n","L 211.342137 0 \n","L 0 0 \n","L 0 264.183469 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 40.603125 226.627219 \n","L 156.571125 226.627219 \n","L 156.571125 9.187219 \n","L 40.603125 9.187219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p84e6a8e056)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAHQAAADaCAYAAAB3jGa5AAAR5UlEQVR4nO1de5DVxZXumdvzfs84w/CUmRERw8iIKCCigyYmZNWNblXEuFkKRsMj6xqrotRuQu1Dza7ZNSVWiWZB1DVilVsrGLBSJFkeQgL4wLiiiAw4wygC82De9zWP/Weru79z6/adB+PMnD3fX6f7u/f3u1Xndp86p0+fk1S0/NV+5eC9J79j5CtuXedS6ucbfqTi4ZEHn4Jxw74njfzJmQ7gWsJhGN+9aoOR//lf7gdu1cIyIxcu+jFwzz/3EIxrfvwfRp5YVQVcOITvbKk9aeSqW64F7k+v7zTy12u+C9zvf/krGN/5oxVG3vaLzcDds24VjF994pdG/v7frQbu5Z89Z+TlP1kD3EuPPwvjFT9da+QXHtsIXLISsIIolBlEocyguz44ABPrds60g9QM4F7cU2fkp5dV4ZNyi2HYHe4xcl5mCnC9/WC2lUpJN2JnpA+opKQkOyDfi/biZ5Xz2b4+z3OUUqqffJcJZIUygyiUGXTZ0jtg4o3N24ycN3secB8f/NDIpasWAJc2aTqMO0J2y81O18CFo734K9KyjNgVIZwLsk1GesnWnZTsfBS5mC13gFxyfOr/vuvnv2rICmUGUSgziEKZQb9Qcx1MVB9+z8jfXHI5cK/9614jF2anAjelbAKMO4LWhhbnpgHXGQrgr3BsaEfY404QtyU8CLclOZn8d51njTU7OBzICmUGUSgziEKZQc+5NB8mlq+xfuk9lROBe80J72Wkoh2svPwSGJ/pChp5ls4BLj0F/0c6M9PIwUiPigvqh/bE90NjbGiA2lDL+/zQRL9hqEhSI2O4ZYUygyiUGfTRhjaY+PtvzDBygMS9Jl5jT/b7SGhtUUU+jE+32S03hWx3qRrHaRnWrQn6Qn8EMaG/ZGsGBhP6i8FQt2OC0XCHZIUygyiUGUShzKBrXnwXJvatqzZyOnFN7lpSbuSuMLoXc0vyYbz16FkjJxNbTG1oepbNWAiS5/a74T4a+usZTsZCf3xuHENWKDOIQplBf7pjO0xsvtkmNn9vzhTg7qmcZOSmjghwpfnpMG5o6jQydXFSiRuT6W65xG0hXwUMK2MBXJP470i0GSePUMRnqJAVygyiUGYQhTKDTrtyPkysf3qPka/8x9uBu768yMiHPmsBbn5ZIYzPnO8yMk2IDgTQ7mRl2eyHUMTjthDEuC1u6K+f2tC4j2EFWaHMIAplBlEoM+gND94IE6vXPmXkTYfmALdkps1YOPxFK3DVM/GyUmOj9UOprcskIcWcHGtDwzGhvzi/XPn9UAn9CVhAFMoM+i+uwvDeprvvNPLefceBO/ud2UY+WItuS181bn/tLe1G7gpjOC87DS8v5WXbjIXPv8R6DDF3SR1EqNsS8GUsxH1MLDfK23HyMN4pK5QZRKHMIAplBt3cicdgzy272sjXvrYduD/U32Tk4yeagOsk7kbwgs0m7AwhN5EcteVnWrflFAn90aM3F2OhxsJY83hkhTKDKJQZRKHMoNftPAYTL95rbSiNu23eX2/ks/VngaMpKarD2ti27qj3RxRku6G/gaegRGOOz5wUFPLbaebhQLPjExXNGGuQFcoMolBm0G5dIqWUOnDdVCOnzZwL3OH9n9jBuVPA1bV0wVgFbejvy+4gcqoARsVZtnRclLgtvYNwW9ytc1ihv4uEUQkbfuVvFIwoRKHMIAplBu3WCFJKqZpnDxq5uvoK4HZtfMkOiFtwiGQwqGjIiKcuoA2l4byiLHucFo2gi9PjfpbYJOq2uLWIBpOxwAmyQplBFMoMolBm0MtX3wYTbkuJmvvXA7drS7YdRNAuHiYpKa6NOtUUAor6loUZrh8ajf/ZJPz/+fxQRRMCvX7o0MKCYxGyQplBFMoM2q1LpJRSO3bfYuS5UzFEl19pS5a31n4KHM1gcC8OnXYu/yoVu+XmpdottyeKob8empXggGb9JTlHI709eGoz1Au/iTAaW7LvlbJCmUEUygyiUGbQGSl4cWjzDxcZuYiUIV/qlCzfHsRuf+fqv8Qnp9mSqWfP49EadTdyPTa01xf6640f+uvpx+f4sxJ8LUDiUmMSskKZQRTKDHrzO/Uw8cPrbZ2ijiBGbWqusRebjnxyHrjjv9uNT87MN2IzcVvovU532491W+JHinpiSsNZMWHGwiiftozUVi4rlBlEocwgCmUGvX7DHpj4sxm2QxK9yHTFJNvd4aoZ2AXi+BtY6lyV2lKs7uVfpWJDdmlul4gIvtOXsUBtKHRP6qecxzWJy4w/yAplBlEoM4hCmUGrho9gYs1rfzJyeWkucBvLK428mLT1+M8AFsLILbDfbf8SLzbF2lAn/BjF7AY4PkvGMKXXhvYN5vhsEGFBegnKd5QlbT4Ew4UolBn0vGV3wcThra8b+fjV1wPX/K2ZRr6qOA+flIcNYfOLrIvTfuJj4GhT9QKnvKrqQbcl6gn9RaPxQ3/0YumgQm3jOAlbVigziEKZQRTKDPq5ZVUwMW+/tXetH2LXpSMNNxi5ciLa0Mwp02FcUmKTsk8HMfRHW3lMyHP+V714ZBf1uC29nowF1ZcgY2GATdUlY0EwqhCFMoMolBl0eQle+F3/wM1GfvThDcBtPnTayC/9JRbUmFaOfujkS+xz341ihmAnSTPRbtsP4oeGeh17O6jjs4H7ocOpTzvWICuUGUShzKAP1OIlo9ULphv50bIq4PbttSXL01dcCxzNYJiYl6bioS2Mrol2jyWI2xJyLx0lOG1xLyslzFi4aOVVx9Z2LSuUGUShzCAKZQZ937OHYOLtx75l5PmLsU7R4Vf+y8i9ffcCt7iCHKe5INkMbaSOQsC1byTTIAg2FJ/jD/31Em5oF5LGmo1MBFmhzCAKZQZ9fv8umHh892VGvm/xpcAd3mq3H9rpofIS3HJbQk7Eh5Sfa+7G7w58yx2M2zLwy0rjbVv1QVYoM4hCmUEUygy66Pqvw8SmjW8a+aGtfw1culOyvLEdT1BKSbekQLtjl7Kw3lFTJ7otYMOIDQ31xM9Y6PO5Lf0Jyqu635OMBcFYhSiUGUShzKA3rcXs+Lt+8I6RS8kR2BKnZPmpC1gI48YibKoedrLaA/l4tNbU5em0RGxoR9jnh5LMB+2EBmMuK8V/ZQwu1tHaKFwllhXKDKJQZtDVl+NWuXSlvbwUJpeB7ptvuy69VX8BuFtnlcI4K81ujzkFOcC1dqLLA43nSMiuKzJwtyUpNX7oD1wapS5a1eqx5tbICmUGUSgziEKZQX/W2A0T/3bHlUY+ScqiVk3Jt5/bXQscLSWekWrtXUERsaHdmEzta/ra5V5sIpkPgwv9xX+Hzwwmj7MqRrJCmUEUygyiUGbQa526REoptXPNQiM/cxBr6T7+bRv6O/FpI3A0JSU73dq7CROy8bOkhqCvi28n+KEk66/Hk9kXk4Ii3QkF4xCiUGbQbl0ipZT69Y020+/1PSeBW7ekwshN9WeAa+zAbTTfqT00pQiz/o4cOwdjX/ekoNtkXdNEa9+WOwi3ZRS6QozUnVRZocwgCmUGUSgzaDVpJkw8sGG/kbvrsAPhsTPWpVFN6NKcasEMhhml1lUpK84Abv+7nnp+BG5No6RAoqy/QVz4dblx1p3QB1mhzCAKZQZRKDNoty6RUqQ2EQmPPf9ugx2E0Gb+4TS2+bhlZomRKwoxqz7UhWXIoZ4fsUndYeuHBgZlQxOF/sZv43QfZIUygyiUGbRbl0gppV5ZeruRT73/CXC/3XvC+SY2i33nZDOMI06YcHJ2JnChbtxyI54LSUFny00i/gU9bQkEhpax4MNYa5qeCLJCmUEUygyiUGbQNOz2Qs18I6/dmgLcR286BTbyMVP+xKfY8TfoZN0XZaK9DZOG7JChT1p5hJzQX3IAuSipGehzW0ajcfpoeEOyQplBFMoM+nGSMP3z22YZeXn1dOAe2RY0cvZUrGHUXP8FjLucpDE3YUwppVSwA4ahaPxk6kgkfqSIlmL1nrYMsWHdaDSkGw5khTKDKJQZRKHMoDc9swMm/mrOJCN/o6IEuKSyOUaeXoFdII4eex/G7UFr3yYXYsaCCuMFqVA0fugvFLL2NaCpDR1MojV+9WIlWo81GysrlBlEocwgCmUGrUjnwBVbbJ2igz/FbIaFN1kftWwCXuI9SjIYGrtteO8ycllJRdCGdrglywMYbgw7x2c09Of1QwlGI/Q3GpAVygyiUGbQS1fcCRO/eeZFI/f/BLfc+2+YZuQISdB6hWQwfNFpw4QpmvxvSHO7Ns+WG3FOW2JCf300Y2EkLiuNr/1YVigziEKZQRTKDPrJP/8aTOzZu8DIp5vRvVg4rcjItES5KpgEw9omm9kXoO4EcTdaQ86Y2OKoe3xGQ3++7kkktBfzGxyMMzPphaxQZhCFMoMolBl0cQ7arKcfvNHIO45jcYsHF5cbmfpnOVOnwbiuCe0vgNi+xi6fDbVcajpyfhuaoM3HAMuQJ7Kvo1GG3AdZocwgCmUGvf0o1hu6s3KykRc8+t/ArXIuNuVnYohuOslu+KLJlmaNqUNEXIrGLrcWUfwtNyML75nGhv7i/z85lVD1QVYoM4hCmUEUygz6bza8BRM3/MK2+Tj59gfAnTx3nZFnT8WOvlfPwHYhe516DLRdCEWLW241Fe2ka0M1PYYbROiPUz0/7zu/8jcKRhSiUGYQhTKDDh49CBMP77BlyFVjHXC/+h/rsz42CbP+FpejTd2+62Mjd0fQ1lGj1ea0/dAppCauczNtcDYU7bbv+MwHSUERjCpEocygK759B0zsfN4pWV44GbhtzuXgR26qAG5WUS6M2y/YBO6uMHaMoJl9brfCQApmJYSdhO2Y0B4N/Q0xK2E0uhOOmKs0Mo8VjBZEocwgCmUGvWXldTBx06EjRr50XhVw9X/8o5Eb26uBK8nFBuyqrcmI7UFiQ8kRWYfTIiQllVxWarMFNmLcFl9hjER1igZYGGOsXehNBFmhzCAKZQZ91TSM8Kxca8urFmfh9vfELluP4UQL1hq6tQRLxanuViOeIxWsVQpuz52O20IjRSpqv5soUqQDX73bMtYgK5QZRKHMIAplBv0h6eaw/pbLjHyeXEh6wunCdKAev3fbbLys5NYiaugIIpeG3Qq7u+x7qNuiehyXJoW6LQO/kOSrv8AJskKZQRTKDKJQZtArX3gHJt762yVGnl6Mtq5yUaWR36vFth4x2fGOj3iiifihxIa6bT9yCzATwr0crOmFX2/oj3Ce7HivjzrOsuplhTKDKJQZdO2bb8DEv99cZuQHFpUDt3LJdCP/00tHgGujJyrOPtbgXFxSSqlAZvwtt7i0AJ/juC0BGtq7SHUUhhP6G41kah9khTKDKJQZRKHMoNO/tgAm/uHp3Ua+68qJwN1cZi/1PnT6c+Bi6hal2EtHZ4gNTcvA47NuJyshNTV+K48UmvVHXBMN3QkHbl99GI6JlM5KgmFDFMoMolBm0G5dIqWU+sHap4y897NG4L4316lF1NwAHE1JURk2k/78ebSh6Zl4qbf7rL0ElU7bajkhxJi6uzSzz+uH+sqXx6XGHWSFMoMolBm0W5dIKaU2LbMly7fsqwNuWdVUO4hgFsL+OsxgUDmXGLG1Gbn8Isw0dLMb0tI8W24CtyUwxDoK4+1ExQdZocwgCmUGUSgz6EbnopBSSj17d5WR561+Gbi6e6+xA5L9fqS2CcYZBdZOdrWiSzPlUqxp5GbHp9PQn89tIRiq2+Kzr4mOx8bY6ZmsUG4QhTKDfvjXH8HEy9+fawefI7f92Fk7KJwC3MkT52GcW2gjRcHP64DLyZkFY3fLzfC5LQkiRb7LSj6XhhNkhTKDKJQZRKHMoN/csg0m9i9wTlSyC4F7dc8pI+dNmwpc62k8fZl9Q5WRz5Gms7lZpLtDr80YzKBui2MnUz0lyJUaetYfp2axskKZQRTKDKJQZtBuZoFSStVstLWIiqvmAffZ2+8bee43FwJ35IPDMJ5UssjIR8lRW352/A5JGanED3WQMPTnzUrgYyd9kBXKDKJQZtAr19wGE1se3WjklevXInfgt0auqrgduCNkW51S5FxIIvWE8jPJlusgxm1xEJOxQPD/pemrD7JCmUEUygyiUGb4XxLztoh576hpAAAAAElFTkSuQmCC\" id=\"image16230a3c51\" transform=\"scale(1 -1)translate(0 -218)\" x=\"40.603125\" y=\"-8.627219\" width=\"116\" height=\"218\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"md656a0e928\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#md656a0e928\" x=\"42.415125\" y=\"226.627219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(39.233875 241.225656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#md656a0e928\" x=\"114.895125\" y=\"226.627219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 20 -->\n","      <g transform=\"translate(108.532625 241.225656)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Column (encoding dimension) -->\n","     <g transform=\"translate(23.498844 254.903781)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-43\" d=\"M 4122 4306 \n","L 4122 3641 \n","Q 3803 3938 3442 4084 \n","Q 3081 4231 2675 4231 \n","Q 1875 4231 1450 3742 \n","Q 1025 3253 1025 2328 \n","Q 1025 1406 1450 917 \n","Q 1875 428 2675 428 \n","Q 3081 428 3442 575 \n","Q 3803 722 4122 1019 \n","L 4122 359 \n","Q 3791 134 3420 21 \n","Q 3050 -91 2638 -91 \n","Q 1578 -91 968 557 \n","Q 359 1206 359 2328 \n","Q 359 3453 968 4101 \n","Q 1578 4750 2638 4750 \n","Q 3056 4750 3426 4639 \n","Q 3797 4528 4122 4306 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n","L 1178 4863 \n","L 1178 0 \n","L 603 0 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6d\" d=\"M 3328 2828 \n","Q 3544 3216 3844 3400 \n","Q 4144 3584 4550 3584 \n","Q 5097 3584 5394 3201 \n","Q 5691 2819 5691 2113 \n","L 5691 0 \n","L 5113 0 \n","L 5113 2094 \n","Q 5113 2597 4934 2840 \n","Q 4756 3084 4391 3084 \n","Q 3944 3084 3684 2787 \n","Q 3425 2491 3425 1978 \n","L 3425 0 \n","L 2847 0 \n","L 2847 2094 \n","Q 2847 2600 2669 2842 \n","Q 2491 3084 2119 3084 \n","Q 1678 3084 1418 2786 \n","Q 1159 2488 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1356 3278 1631 3431 \n","Q 1906 3584 2284 3584 \n","Q 2666 3584 2933 3390 \n","Q 3200 3197 3328 2828 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \n","Q 1566 4138 1362 3434 \n","Q 1159 2731 1159 2009 \n","Q 1159 1288 1364 580 \n","Q 1569 -128 1984 -844 \n","L 1484 -844 \n","Q 1016 -109 783 600 \n","Q 550 1309 550 2009 \n","Q 550 2706 781 3412 \n","Q 1013 4119 1484 4856 \n","L 1984 4856 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n","L 3122 2828 \n","Q 2878 2963 2633 3030 \n","Q 2388 3097 2138 3097 \n","Q 1578 3097 1268 2742 \n","Q 959 2388 959 1747 \n","Q 959 1106 1268 751 \n","Q 1578 397 2138 397 \n","Q 2388 397 2633 464 \n","Q 2878 531 3122 666 \n","L 3122 134 \n","Q 2881 22 2623 -34 \n","Q 2366 -91 2075 -91 \n","Q 1284 -91 818 406 \n","Q 353 903 353 1747 \n","Q 353 2603 823 3093 \n","Q 1294 3584 2113 3584 \n","Q 2378 3584 2631 3529 \n","Q 2884 3475 3122 3366 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-67\" d=\"M 2906 1791 \n","Q 2906 2416 2648 2759 \n","Q 2391 3103 1925 3103 \n","Q 1463 3103 1205 2759 \n","Q 947 2416 947 1791 \n","Q 947 1169 1205 825 \n","Q 1463 481 1925 481 \n","Q 2391 481 2648 825 \n","Q 2906 1169 2906 1791 \n","z\n","M 3481 434 \n","Q 3481 -459 3084 -895 \n","Q 2688 -1331 1869 -1331 \n","Q 1566 -1331 1297 -1286 \n","Q 1028 -1241 775 -1147 \n","L 775 -588 \n","Q 1028 -725 1275 -790 \n","Q 1522 -856 1778 -856 \n","Q 2344 -856 2625 -561 \n","Q 2906 -266 2906 331 \n","L 2906 616 \n","Q 2728 306 2450 153 \n","Q 2172 0 1784 0 \n","Q 1141 0 747 490 \n","Q 353 981 353 1791 \n","Q 353 2603 747 3093 \n","Q 1141 3584 1784 3584 \n","Q 2172 3584 2450 3431 \n","Q 2728 3278 2906 2969 \n","L 2906 3500 \n","L 3481 3500 \n","L 3481 434 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \n","L 1013 4856 \n","Q 1481 4119 1714 3412 \n","Q 1947 2706 1947 2009 \n","Q 1947 1309 1714 600 \n","Q 1481 -109 1013 -844 \n","L 513 -844 \n","Q 928 -128 1133 580 \n","Q 1338 1288 1338 2009 \n","Q 1338 2731 1133 3434 \n","Q 928 4138 513 4856 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-43\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"69.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-6c\" x=\"131.005859\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"158.789062\"/>\n","      <use xlink:href=\"#DejaVuSans-6d\" x=\"222.167969\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"319.580078\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"382.958984\"/>\n","      <use xlink:href=\"#DejaVuSans-28\" x=\"414.746094\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"453.759766\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"515.283203\"/>\n","      <use xlink:href=\"#DejaVuSans-63\" x=\"578.662109\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"633.642578\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"694.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"758.300781\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"786.083984\"/>\n","      <use xlink:href=\"#DejaVuSans-67\" x=\"849.462891\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"912.939453\"/>\n","      <use xlink:href=\"#DejaVuSans-64\" x=\"944.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"1008.203125\"/>\n","      <use xlink:href=\"#DejaVuSans-6d\" x=\"1035.986328\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"1133.398438\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"1194.921875\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"1258.300781\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"1310.400391\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"1338.183594\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"1399.365234\"/>\n","      <use xlink:href=\"#DejaVuSans-29\" x=\"1462.744141\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"m76e041405d\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 0 -->\n","      <g transform=\"translate(27.240625 14.798437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"47.239219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_5\">\n","      <!-- 10 -->\n","      <g transform=\"translate(20.878125 51.038437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"83.479219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 20 -->\n","      <g transform=\"translate(20.878125 87.278437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"119.719219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 30 -->\n","      <g transform=\"translate(20.878125 123.518437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-33\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"155.959219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 40 -->\n","      <g transform=\"translate(20.878125 159.758437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m76e041405d\" x=\"40.603125\" y=\"192.199219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 50 -->\n","      <g transform=\"translate(20.878125 195.998437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Row (position) -->\n","     <g transform=\"translate(14.798438 153.600187)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-52\" d=\"M 2841 2188 \n","Q 3044 2119 3236 1894 \n","Q 3428 1669 3622 1275 \n","L 4263 0 \n","L 3584 0 \n","L 2988 1197 \n","Q 2756 1666 2539 1819 \n","Q 2322 1972 1947 1972 \n","L 1259 1972 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","L 2053 4666 \n","Q 2853 4666 3247 4331 \n","Q 3641 3997 3641 3322 \n","Q 3641 2881 3436 2590 \n","Q 3231 2300 2841 2188 \n","z\n","M 1259 4147 \n","L 1259 2491 \n","L 2053 2491 \n","Q 2509 2491 2742 2702 \n","Q 2975 2913 2975 3322 \n","Q 2975 3731 2742 3939 \n","Q 2509 4147 2053 4147 \n","L 1259 4147 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-77\" d=\"M 269 3500 \n","L 844 3500 \n","L 1563 769 \n","L 2278 3500 \n","L 2956 3500 \n","L 3675 769 \n","L 4391 3500 \n","L 4966 3500 \n","L 4050 0 \n","L 3372 0 \n","L 2619 2869 \n","L 1863 0 \n","L 1184 0 \n","L 269 3500 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-52\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"64.982422\"/>\n","      <use xlink:href=\"#DejaVuSans-77\" x=\"126.164062\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"207.951172\"/>\n","      <use xlink:href=\"#DejaVuSans-28\" x=\"239.738281\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"278.751953\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"342.228516\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"403.410156\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"455.509766\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"483.292969\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"522.501953\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"550.285156\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"611.466797\"/>\n","      <use xlink:href=\"#DejaVuSans-29\" x=\"674.845703\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 40.603125 226.627219 \n","L 40.603125 9.187219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 156.571125 226.627219 \n","L 156.571125 9.187219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 40.603125 226.627219 \n","L 156.571125 226.627219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 40.603125 9.187219 \n","L 156.571125 9.187219 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 166.336125 183.139219 \n","L 172.859325 183.139219 \n","L 172.859325 52.675219 \n","L 166.336125 52.675219 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path clip-path=\"url(#p5382f2e3c7)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAcAAACDCAYAAABBcwEdAAAAqElEQVR4nO2WQQoEMQgEXcj/vzuHTXRfYAVaJBnYuTbVapuE+TzfCEu+4blmA7QLSScyXkVel+0J0pgE8V3LRnLJthtSr3mCTLW+mlC0VDPVbCyqybZOtkROnBNt5YTQdtNQS7YoTjlbPkO47EK2PQ0dqFl4GPUzJI/yF82Ge35ZNluB29vVbRRGAVG3RZL/MA401EQWEiLSfMni7LHtEddtDeli5Pv8AVjrYLu4ozIGAAAAAElFTkSuQmCC\" id=\"image9ef40441d3\" transform=\"scale(1 -1)translate(0 -131)\" x=\"166\" y=\"-52\" width=\"7\" height=\"131\"/>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_9\">\n","      <defs>\n","       <path id=\"m23a738a852\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m23a738a852\" x=\"172.859325\" y=\"183.139219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- −1.0 -->\n","      <g transform=\"translate(179.859325 186.938437)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \n","L 4684 2272 \n","L 4684 1741 \n","L 678 1741 \n","L 678 2272 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"83.789062\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"179.199219\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m23a738a852\" x=\"172.859325\" y=\"150.523219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- −0.5 -->\n","      <g transform=\"translate(179.859325 154.322437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-2212\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"83.789062\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"147.412109\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"179.199219\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#m23a738a852\" x=\"172.859325\" y=\"117.907219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(179.859325 121.706437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_10\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m23a738a852\" x=\"172.859325\" y=\"85.291219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 0.5 -->\n","      <g transform=\"translate(179.859325 89.090437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_11\">\n","     <g id=\"line2d_13\">\n","      <g>\n","       <use xlink:href=\"#m23a738a852\" x=\"172.859325\" y=\"52.675219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_15\">\n","      <!-- 1.0 -->\n","      <g transform=\"translate(179.859325 56.474437)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_9\">\n","    <path d=\"M 166.336125 183.139219 \n","L 169.597725 183.139219 \n","L 172.859325 183.139219 \n","L 172.859325 52.675219 \n","L 169.597725 52.675219 \n","L 166.336125 52.675219 \n","L 166.336125 183.139219 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p84e6a8e056\">\n","   <rect x=\"40.603125\" y=\"9.187219\" width=\"115.968\" height=\"217.44\"/>\n","  </clipPath>\n","  <clipPath id=\"p5382f2e3c7\">\n","   <rect x=\"166.336125\" y=\"52.675219\" width=\"6.5232\" height=\"130.464\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x288 with 2 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["P = P[0, :, :].unsqueeze(0).unsqueeze(0)\n","d2l.show_heatmaps(P, xlabel='Column (encoding dimension)',\n","                  ylabel='Row (position)', figsize=(3.5, 4), cmap='Blues')"],"id":"a5684c9c"},{"cell_type":"markdown","metadata":{"origin_pos":24,"id":"ce043b8d"},"source":["### 相对位置信息\n","\n","除了捕获绝对位置信息之外，上述的位置编码还允许模型学习得到输入序列中相对位置信息。\n","这是因为对于任何确定的位置偏移$\\delta$，位置$i + \\delta$处\n","的位置编码可以线性投影位置$i$处的位置编码来表示。\n","\n","这种投影的数学解释是，令$\\omega_j = 1/10000^{2j/d}$，\n","对于任何确定的位置偏移$\\delta$，\n"," :eqref:`eq_positional-encoding-def`中的任何一对\n","$(p_{i, 2j}, p_{i, 2j+1})$都可以线性投影到\n","$(p_{i+\\delta, 2j}, p_{i+\\delta, 2j+1})$：\n","\n","$$\\begin{aligned}\n","&\\begin{bmatrix} \\cos(\\delta \\omega_j) & \\sin(\\delta \\omega_j) \\\\  -\\sin(\\delta \\omega_j) & \\cos(\\delta \\omega_j) \\\\ \\end{bmatrix}\n","\\begin{bmatrix} p_{i, 2j} \\\\  p_{i, 2j+1} \\\\ \\end{bmatrix}\\\\\n","=&\\begin{bmatrix} \\cos(\\delta \\omega_j) \\sin(i \\omega_j) + \\sin(\\delta \\omega_j) \\cos(i \\omega_j) \\\\  -\\sin(\\delta \\omega_j) \\sin(i \\omega_j) + \\cos(\\delta \\omega_j) \\cos(i \\omega_j) \\\\ \\end{bmatrix}\\\\\n","=&\\begin{bmatrix} \\sin\\left((i+\\delta) \\omega_j\\right) \\\\  \\cos\\left((i+\\delta) \\omega_j\\right) \\\\ \\end{bmatrix}\\\\\n","=& \n","\\begin{bmatrix} p_{i+\\delta, 2j} \\\\  p_{i+\\delta, 2j+1} \\\\ \\end{bmatrix},\n","\\end{aligned}$$\n","\n","$2\\times 2$投影矩阵不依赖于任何位置的索引$i$。\n","\n","## 小结\n","\n","* 在自注意力中，查询、键和值都来自同一组输入。\n","* 卷积神经网络和自注意力都拥有并行计算的优势，而且自注意力的最大路径长度最短。但是因为其计算复杂度是关于序列长度的二次方，所以在很长的序列中计算会非常慢。\n","* 为了使用序列的顺序信息，我们可以通过在输入表示中添加位置编码，来注入绝对的或相对的位置信息。\n","\n","## 练习\n","\n","1. 假设我们设计一个深度架构，通过堆叠基于位置编码的自注意力层来表示序列。可能会存在什么问题？\n","1. 你能设计一种可学习的位置编码方法吗？\n"],"id":"ce043b8d"},{"cell_type":"markdown","metadata":{"origin_pos":0,"id":"c783c57f"},"source":["# Transformer\n",":label:`sec_transformer`\n","\n","我们在 :numref:`subsec_cnn-rnn-self-attention`中比较了卷积神经网络（CNN）、循环神经网络（RNN）和自注意力（self-attention）。值得注意的是，自注意力同时具有并行计算和最短的最大路径长度这两个优势。因此，使用自注意力来设计深度架构是很有吸引力的。对比之前仍然依赖循环神经网络实现输入表示的自注意力模型 :cite:`Cheng.Dong.Lapata.2016,Lin.Feng.Santos.ea.2017,Paulus.Xiong.Socher.2017`，transformer模型完全基于注意力机制，没有任何卷积层或循环神经网络层 :cite:`Vaswani.Shazeer.Parmar.ea.2017`。尽管transformer最初是应用于在文本数据上的序列到序列学习，但现在已经推广到各种现代的深度学习中，例如语言、视觉、语音和强化学习领域。\n","\n","## 模型\n","\n","Transformer作为编码器－解码器架构的一个实例，其整体架构图在 :numref:`fig_transformer`中展示。正如所见到的，transformer是由编码器和解码器组成的。与 :numref:`fig_s2s_attention_details`中基于Bahdanau注意力实现的序列到序列的学习相比，transformer的编码器和解码器是基于自注意力的模块叠加而成的，源（输入）序列和目标（输出）序列的*嵌入*（embedding）表示将加上*位置编码*（positional encoding），再分别输入到编码器和解码器中。\n","\n","![transformer架构](http://d2l.ai/_images/transformer.svg)\n",":width:`500px`\n",":label:`fig_transformer`\n","\n","图 :numref:`fig_transformer`中概述了transformer的架构。从宏观角度来看，transformer的编码器是由多个相同的层叠加而成的，每个层都有两个子层（子层表示为$\\mathrm{sublayer}$）。第一个子层是*多头自注意力*（multi-head self-attention）汇聚；第二个子层是*基于位置的前馈网络*（positionwise feed-forward network）。具体来说，在计算编码器的自注意力时，查询、键和值都来自前一个编码器层的输出。受 :numref:`sec_resnet`中残差网络的启发，每个子层都采用了*残差连接*（residual connection）。在transformer中，对于序列中任何位置的任何输入$\\mathbf{x} \\in \\mathbb{R}^d$，都要求满足$\\mathrm{sublayer}(\\mathbf{x}) \\in \\mathbb{R}^d$，以便残差连接满足$\\mathbf{x} + \\mathrm{sublayer}(\\mathbf{x}) \\in \\mathbb{R}^d$。在残差连接的加法计算之后，紧接着应用*层规范化*（layer normalization） :cite:`Ba.Kiros.Hinton.2016`。因此，输入序列对应的每个位置，transformer编码器都将输出一个$d$维表示向量。\n","\n","Transformer解码器也是由多个相同的层叠加而成的，并且层中使用了残差连接和层规范化。除了编码器中描述的两个子层之外，解码器还在这两个子层之间插入了第三个子层，称为*编码器－解码器注意力*（encoder-decoder attention）层。在编码器－解码器注意力中，查询来自前一个解码器层的输出，而键和值来自整个编码器的输出。在解码器自注意力中，查询、键和值都来自上一个解码器层的输出。但是，解码器中的每个位置只能考虑该位置之前的所有位置。这种*掩蔽*（masked）注意力保留了*自回归*（auto-regressive）属性，确保预测仅依赖于已生成的输出词元。\n","\n","我们已经描述并实现了基于缩放点积多头注意力 :numref:`sec_multihead-attention`和位置编码 :numref:`subsec_positional-encoding`。接下来，我们将实现transformer模型的剩余部分。\n"],"id":"c783c57f"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:51.151536Z","iopub.status.busy":"2022-07-31T03:01:51.150930Z","iopub.status.idle":"2022-07-31T03:01:53.130502Z","shell.execute_reply":"2022-07-31T03:01:53.129568Z"},"origin_pos":2,"tab":["pytorch"],"id":"97904f88"},"outputs":[],"source":["import math\n","import pandas as pd\n","import torch\n","from torch import nn\n","from d2l import torch as d2l"],"id":"97904f88"},{"cell_type":"markdown","metadata":{"origin_pos":4,"id":"7d99b60e"},"source":["## [**基于位置的前馈网络**]\n","\n","基于位置的前馈网络对序列中的所有位置的表示进行变换时使用的是同一个多层感知机（MLP），这就是称前馈网络是*基于位置的*（positionwise）的原因。在下面的实现中，输入`X`的形状（批量大小，时间步数或序列长度，隐单元数或特征维度）将被一个两层的感知机转换成形状为（批量大小，时间步数，`ffn_num_outputs`）的输出张量。\n"],"id":"7d99b60e"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.135645Z","iopub.status.busy":"2022-07-31T03:01:53.135235Z","iopub.status.idle":"2022-07-31T03:01:53.141481Z","shell.execute_reply":"2022-07-31T03:01:53.140610Z"},"origin_pos":6,"tab":["pytorch"],"id":"534dc7e0"},"outputs":[],"source":["#@save\n","class PositionWiseFFN(nn.Module):\n","    \"\"\"基于位置的前馈网络\"\"\"\n","    def __init__(self, ffn_num_input, ffn_num_hiddens, ffn_num_outputs,\n","                 **kwargs):\n","        super(PositionWiseFFN, self).__init__(**kwargs)\n","        self.dense1 = nn.Linear(ffn_num_input, ffn_num_hiddens)\n","        self.relu = nn.ReLU()\n","        self.dense2 = nn.Linear(ffn_num_hiddens, ffn_num_outputs)\n","\n","    def forward(self, X):\n","        return self.dense2(self.relu(self.dense1(X)))"],"id":"534dc7e0"},{"cell_type":"markdown","metadata":{"origin_pos":8,"id":"b4206344"},"source":["下面的例子显示，[**改变张量的最里层维度的尺寸**]，会改变成基于位置的前馈网络的输出尺寸。因为用同一个多层感知机对所有位置上的输入进行变换，所以当所有这些位置的输入相同时，它们的输出也是相同的。\n"],"id":"b4206344"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.145862Z","iopub.status.busy":"2022-07-31T03:01:53.145458Z","iopub.status.idle":"2022-07-31T03:01:53.155277Z","shell.execute_reply":"2022-07-31T03:01:53.154413Z"},"origin_pos":10,"tab":["pytorch"],"id":"acd6c21f","outputId":"afd47e9c-a6ff-43c1-c6b2-ea39cdb19d19"},"outputs":[{"data":{"text/plain":["tensor([[-1.2386, -0.9917,  0.4708, -0.4516, -0.3069,  0.0447,  0.9740,  0.1313],\n","        [-1.2386, -0.9917,  0.4708, -0.4516, -0.3069,  0.0447,  0.9740,  0.1313],\n","        [-1.2386, -0.9917,  0.4708, -0.4516, -0.3069,  0.0447,  0.9740,  0.1313]],\n","       grad_fn=<SelectBackward0>)"]},"execution_count":3,"metadata":{},"output_type":"execute_result"}],"source":["ffn = PositionWiseFFN(4, 4, 8)\n","ffn.eval()\n","ffn(torch.ones((2, 3, 4)))[0]"],"id":"acd6c21f"},{"cell_type":"markdown","metadata":{"origin_pos":12,"id":"a60f9e04"},"source":["## 残差连接和层规范化\n","\n","现在让我们关注 :numref:`fig_transformer`中的“*加法和规范化*（add&norm）”组件。正如在本节开头所述，这是由残差连接和紧随其后的层规范化组成的。两者都是构建有效的深度架构的关键。\n","\n","在 :numref:`sec_batch_norm`中，我们解释了在一个小批量的样本内基于批量规范化对数据进行重新中心化和重新缩放的调整。层规范化和批量规范化的目标相同，但层规范化是基于特征维度进行规范化。尽管批量规范化在计算机视觉中被广泛应用，但在自然语言处理任务中（输入通常是变长序列）批量规范化通常不如层规范化的效果好。\n","\n","以下代码[**对比不同维度的层规范化和批量规范化的效果**]。\n"],"id":"a60f9e04"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.158307Z","iopub.status.busy":"2022-07-31T03:01:53.158031Z","iopub.status.idle":"2022-07-31T03:01:53.167695Z","shell.execute_reply":"2022-07-31T03:01:53.166957Z"},"origin_pos":14,"tab":["pytorch"],"id":"226dff63","outputId":"84a67d04-b86d-4749-aa02-e4919b16f298"},"outputs":[{"name":"stdout","output_type":"stream","text":["layer norm: tensor([[-1.0000,  1.0000],\n","        [-1.0000,  1.0000]], grad_fn=<NativeLayerNormBackward0>) \n","batch norm: tensor([[-1.0000, -1.0000],\n","        [ 1.0000,  1.0000]], grad_fn=<NativeBatchNormBackward0>)\n"]}],"source":["ln = nn.LayerNorm(2)\n","bn = nn.BatchNorm1d(2)\n","X = torch.tensor([[1, 2], [2, 3]], dtype=torch.float32)\n","# 在训练模式下计算X的均值和方差\n","print('layer norm:', ln(X), '\\nbatch norm:', bn(X))"],"id":"226dff63"},{"cell_type":"markdown","metadata":{"origin_pos":16,"id":"77cc1a9a"},"source":["现在我们可以[**使用残差连接和层规范化**]来实现`AddNorm`类。暂退法也被作为正则化方法使用。\n"],"id":"77cc1a9a"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.170695Z","iopub.status.busy":"2022-07-31T03:01:53.170340Z","iopub.status.idle":"2022-07-31T03:01:53.175232Z","shell.execute_reply":"2022-07-31T03:01:53.174526Z"},"origin_pos":18,"tab":["pytorch"],"id":"0b79dc94"},"outputs":[],"source":["#@save\n","class AddNorm(nn.Module):\n","    \"\"\"残差连接后进行层规范化\"\"\"\n","    def __init__(self, normalized_shape, dropout, **kwargs):\n","        super(AddNorm, self).__init__(**kwargs)\n","        self.dropout = nn.Dropout(dropout)\n","        self.ln = nn.LayerNorm(normalized_shape)\n","\n","    def forward(self, X, Y):\n","        return self.ln(self.dropout(Y) + X)"],"id":"0b79dc94"},{"cell_type":"markdown","metadata":{"origin_pos":20,"id":"1a2455e9"},"source":["残差连接要求两个输入的形状相同，以便[**加法操作后输出张量的形状相同**]。\n"],"id":"1a2455e9"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.178489Z","iopub.status.busy":"2022-07-31T03:01:53.177918Z","iopub.status.idle":"2022-07-31T03:01:53.185116Z","shell.execute_reply":"2022-07-31T03:01:53.184484Z"},"origin_pos":22,"tab":["pytorch"],"id":"e9a5e8b1","outputId":"03569ff3-9c9a-4252-c0e2-43bcbeb0ea41"},"outputs":[{"data":{"text/plain":["torch.Size([2, 3, 4])"]},"execution_count":6,"metadata":{},"output_type":"execute_result"}],"source":["add_norm = AddNorm([3, 4], 0.5)\n","add_norm.eval()\n","add_norm(torch.ones((2, 3, 4)), torch.ones((2, 3, 4))).shape"],"id":"e9a5e8b1"},{"cell_type":"markdown","metadata":{"origin_pos":24,"id":"80ef2b92"},"source":["## 编码器\n","\n","有了组成transformer编码器的基础组件，现在可以先[**实现编码器中的一个层**]。下面的`EncoderBlock`类包含两个子层：多头自注意力和基于位置的前馈网络，这两个子层都使用了残差连接和紧随的层规范化。\n"],"id":"80ef2b92"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.189671Z","iopub.status.busy":"2022-07-31T03:01:53.189151Z","iopub.status.idle":"2022-07-31T03:01:53.195245Z","shell.execute_reply":"2022-07-31T03:01:53.194560Z"},"origin_pos":26,"tab":["pytorch"],"id":"0619ca28"},"outputs":[],"source":["#@save\n","class EncoderBlock(nn.Module):\n","    \"\"\"transformer编码器块\"\"\"\n","    def __init__(self, key_size, query_size, value_size, num_hiddens,\n","                 norm_shape, ffn_num_input, ffn_num_hiddens, num_heads,\n","                 dropout, use_bias=False, **kwargs):\n","        super(EncoderBlock, self).__init__(**kwargs)\n","        self.attention = d2l.MultiHeadAttention(\n","            key_size, query_size, value_size, num_hiddens, num_heads, dropout,\n","            use_bias)\n","        self.addnorm1 = AddNorm(norm_shape, dropout)\n","        self.ffn = PositionWiseFFN(\n","            ffn_num_input, ffn_num_hiddens, num_hiddens)\n","        self.addnorm2 = AddNorm(norm_shape, dropout)\n","\n","    def forward(self, X, valid_lens):\n","        Y = self.addnorm1(X, self.attention(X, X, X, valid_lens))\n","        return self.addnorm2(Y, self.ffn(Y))"],"id":"0619ca28"},{"cell_type":"markdown","metadata":{"origin_pos":28,"id":"81babaa4"},"source":["正如我们所看到的，[**transformer编码器中的任何层都不会改变其输入的形状**]。\n"],"id":"81babaa4"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.199528Z","iopub.status.busy":"2022-07-31T03:01:53.199037Z","iopub.status.idle":"2022-07-31T03:01:53.210586Z","shell.execute_reply":"2022-07-31T03:01:53.209930Z"},"origin_pos":30,"tab":["pytorch"],"id":"a72f89f5","outputId":"55b1e239-db53-4ff8-a3f9-617c7740b0b6"},"outputs":[{"data":{"text/plain":["torch.Size([2, 100, 24])"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["X = torch.ones((2, 100, 24))\n","valid_lens = torch.tensor([3, 2])\n","encoder_blk = EncoderBlock(24, 24, 24, 24, [100, 24], 24, 48, 8, 0.5)\n","encoder_blk.eval()\n","encoder_blk(X, valid_lens).shape"],"id":"a72f89f5"},{"cell_type":"markdown","metadata":{"origin_pos":32,"id":"c999d576"},"source":["在实现下面的[**transformer编码器**]的代码中，我们堆叠了`num_layers`个`EncoderBlock`类的实例。由于我们使用的是值范围在$-1$和$1$之间的固定位置编码，因此通过学习得到的输入的嵌入表示的值需要先乘以嵌入维度的平方根进行重新缩放，然后再与位置编码相加。\n"],"id":"c999d576"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.214931Z","iopub.status.busy":"2022-07-31T03:01:53.214431Z","iopub.status.idle":"2022-07-31T03:01:53.222175Z","shell.execute_reply":"2022-07-31T03:01:53.221497Z"},"origin_pos":34,"tab":["pytorch"],"id":"be0d244b"},"outputs":[],"source":["#@save\n","class TransformerEncoder(d2l.Encoder):\n","    \"\"\"transformer编码器\"\"\"\n","    def __init__(self, vocab_size, key_size, query_size, value_size,\n","                 num_hiddens, norm_shape, ffn_num_input, ffn_num_hiddens,\n","                 num_heads, num_layers, dropout, use_bias=False, **kwargs):\n","        super(TransformerEncoder, self).__init__(**kwargs)\n","        self.num_hiddens = num_hiddens\n","        self.embedding = nn.Embedding(vocab_size, num_hiddens)\n","        self.pos_encoding = d2l.PositionalEncoding(num_hiddens, dropout)\n","        self.blks = nn.Sequential()\n","        for i in range(num_layers):\n","            self.blks.add_module(\"block\"+str(i),\n","                EncoderBlock(key_size, query_size, value_size, num_hiddens,\n","                             norm_shape, ffn_num_input, ffn_num_hiddens,\n","                             num_heads, dropout, use_bias))\n","\n","    def forward(self, X, valid_lens, *args):\n","        # 因为位置编码值在-1和1之间，\n","        # 因此嵌入值乘以嵌入维度的平方根进行缩放，\n","        # 然后再与位置编码相加。\n","        X = self.pos_encoding(self.embedding(X) * math.sqrt(self.num_hiddens))\n","        self.attention_weights = [None] * len(self.blks)\n","        for i, blk in enumerate(self.blks):\n","            X = blk(X, valid_lens)\n","            self.attention_weights[\n","                i] = blk.attention.attention.attention_weights\n","        return X"],"id":"be0d244b"},{"cell_type":"markdown","metadata":{"origin_pos":36,"id":"e745b24d"},"source":["下面我们指定了超参数来[**创建一个两层的transformer编码器**]。\n","Transformer编码器输出的形状是（批量大小，时间步数目，`num_hiddens`）。\n"],"id":"e745b24d"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.226775Z","iopub.status.busy":"2022-07-31T03:01:53.226296Z","iopub.status.idle":"2022-07-31T03:01:53.240164Z","shell.execute_reply":"2022-07-31T03:01:53.239521Z"},"origin_pos":38,"tab":["pytorch"],"id":"6867b160","outputId":"f039302e-caf8-44fc-da56-6d061c715233"},"outputs":[{"data":{"text/plain":["torch.Size([2, 100, 24])"]},"execution_count":10,"metadata":{},"output_type":"execute_result"}],"source":["encoder = TransformerEncoder(\n","    200, 24, 24, 24, 24, [100, 24], 24, 48, 8, 2, 0.5)\n","encoder.eval()\n","encoder(torch.ones((2, 100), dtype=torch.long), valid_lens).shape"],"id":"6867b160"},{"cell_type":"markdown","metadata":{"origin_pos":40,"id":"4c86f8cd"},"source":["## 解码器\n","\n","如 :numref:`fig_transformer`所示，[**transformer解码器也是由多个相同的层组成**]。在`DecoderBlock`类中实现的每个层包含了三个子层：解码器自注意力、“编码器-解码器”注意力和基于位置的前馈网络。这些子层也都被残差连接和紧随的层规范化围绕。\n","\n","正如在本节前面所述，在掩蔽多头解码器自注意力层（第一个子层）中，查询、键和值都来自上一个解码器层的输出。关于*序列到序列模型*（sequence-to-sequence model），在训练阶段，其输出序列的所有位置（时间步）的词元都是已知的；然而，在预测阶段，其输出序列的词元是逐个生成的。因此，在任何解码器时间步中，只有生成的词元才能用于解码器的自注意力计算中。为了在解码器中保留自回归的属性，其掩蔽自注意力设定了参数`dec_valid_lens`，以便任何查询都只会与解码器中所有已经生成词元的位置（即直到该查询位置为止）进行注意力计算。\n"],"id":"4c86f8cd"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.244576Z","iopub.status.busy":"2022-07-31T03:01:53.244075Z","iopub.status.idle":"2022-07-31T03:01:53.253809Z","shell.execute_reply":"2022-07-31T03:01:53.253090Z"},"origin_pos":42,"tab":["pytorch"],"id":"6ef5a28f"},"outputs":[],"source":["class DecoderBlock(nn.Module):\n","    \"\"\"解码器中第i个块\"\"\"\n","    def __init__(self, key_size, query_size, value_size, num_hiddens,\n","                 norm_shape, ffn_num_input, ffn_num_hiddens, num_heads,\n","                 dropout, i, **kwargs):\n","        super(DecoderBlock, self).__init__(**kwargs)\n","        self.i = i\n","        self.attention1 = d2l.MultiHeadAttention(\n","            key_size, query_size, value_size, num_hiddens, num_heads, dropout)\n","        self.addnorm1 = AddNorm(norm_shape, dropout)\n","        self.attention2 = d2l.MultiHeadAttention(\n","            key_size, query_size, value_size, num_hiddens, num_heads, dropout)\n","        self.addnorm2 = AddNorm(norm_shape, dropout)\n","        self.ffn = PositionWiseFFN(ffn_num_input, ffn_num_hiddens,\n","                                   num_hiddens)\n","        self.addnorm3 = AddNorm(norm_shape, dropout)\n","\n","    def forward(self, X, state):\n","        enc_outputs, enc_valid_lens = state[0], state[1]\n","        # 训练阶段，输出序列的所有词元都在同一时间处理，\n","        # 因此state[2][self.i]初始化为None。\n","        # 预测阶段，输出序列是通过词元一个接着一个解码的，\n","        # 因此state[2][self.i]包含着直到当前时间步第i个块解码的输出表示\n","        if state[2][self.i] is None:\n","            key_values = X\n","        else:\n","            key_values = torch.cat((state[2][self.i], X), axis=1)\n","        state[2][self.i] = key_values\n","        if self.training:\n","            batch_size, num_steps, _ = X.shape\n","            # dec_valid_lens的开头:(batch_size,num_steps),\n","            # 其中每一行是[1,2,...,num_steps]\n","            dec_valid_lens = torch.arange(\n","                1, num_steps + 1, device=X.device).repeat(batch_size, 1)\n","        else:\n","            dec_valid_lens = None\n","\n","        # 自注意力\n","        X2 = self.attention1(X, key_values, key_values, dec_valid_lens)\n","        Y = self.addnorm1(X, X2)\n","        # 编码器－解码器注意力。\n","        # enc_outputs的开头:(batch_size,num_steps,num_hiddens)\n","        Y2 = self.attention2(Y, enc_outputs, enc_outputs, enc_valid_lens)\n","        Z = self.addnorm2(Y, Y2)\n","        return self.addnorm3(Z, self.ffn(Z)), state"],"id":"6ef5a28f"},{"cell_type":"markdown","metadata":{"origin_pos":44,"id":"b948b36a"},"source":["为了便于在“编码器－解码器”注意力中进行缩放点积计算和残差连接中进行加法计算，[**编码器和解码器的特征维度都是`num_hiddens`。**]\n"],"id":"b948b36a"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.258104Z","iopub.status.busy":"2022-07-31T03:01:53.257608Z","iopub.status.idle":"2022-07-31T03:01:53.272238Z","shell.execute_reply":"2022-07-31T03:01:53.271545Z"},"origin_pos":46,"tab":["pytorch"],"id":"0a44fc48","outputId":"8d4e1b4c-a2d8-4a8e-8235-dc7c3d5e9d3f"},"outputs":[{"data":{"text/plain":["torch.Size([2, 100, 24])"]},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"source":["decoder_blk = DecoderBlock(24, 24, 24, 24, [100, 24], 24, 48, 8, 0.5, 0)\n","decoder_blk.eval()\n","X = torch.ones((2, 100, 24))\n","state = [encoder_blk(X, valid_lens), valid_lens, [None]]\n","decoder_blk(X, state)[0].shape"],"id":"0a44fc48"},{"cell_type":"markdown","metadata":{"origin_pos":48,"id":"1d75909f"},"source":["现在我们构建了由`num_layers`个`DecoderBlock`实例组成的完整的[**transformer解码器**]。最后，通过一个全连接层计算所有`vocab_size`个可能的输出词元的预测值。解码器的自注意力权重和编码器解码器注意力权重都被存储下来，方便日后可视化的需要。\n"],"id":"1d75909f"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.276720Z","iopub.status.busy":"2022-07-31T03:01:53.276225Z","iopub.status.idle":"2022-07-31T03:01:53.285192Z","shell.execute_reply":"2022-07-31T03:01:53.284530Z"},"origin_pos":50,"tab":["pytorch"],"id":"d19ed317"},"outputs":[],"source":["class TransformerDecoder(d2l.AttentionDecoder):\n","    def __init__(self, vocab_size, key_size, query_size, value_size,\n","                 num_hiddens, norm_shape, ffn_num_input, ffn_num_hiddens,\n","                 num_heads, num_layers, dropout, **kwargs):\n","        super(TransformerDecoder, self).__init__(**kwargs)\n","        self.num_hiddens = num_hiddens\n","        self.num_layers = num_layers\n","        self.embedding = nn.Embedding(vocab_size, num_hiddens)\n","        self.pos_encoding = d2l.PositionalEncoding(num_hiddens, dropout)\n","        self.blks = nn.Sequential()\n","        for i in range(num_layers):\n","            self.blks.add_module(\"block\"+str(i),\n","                DecoderBlock(key_size, query_size, value_size, num_hiddens,\n","                             norm_shape, ffn_num_input, ffn_num_hiddens,\n","                             num_heads, dropout, i))\n","        self.dense = nn.Linear(num_hiddens, vocab_size)\n","\n","    def init_state(self, enc_outputs, enc_valid_lens, *args):\n","        return [enc_outputs, enc_valid_lens, [None] * self.num_layers]\n","\n","    def forward(self, X, state):\n","        X = self.pos_encoding(self.embedding(X) * math.sqrt(self.num_hiddens))\n","        self._attention_weights = [[None] * len(self.blks) for _ in range (2)]\n","        for i, blk in enumerate(self.blks):\n","            X, state = blk(X, state)\n","            # 解码器自注意力权重\n","            self._attention_weights[0][\n","                i] = blk.attention1.attention.attention_weights\n","            # “编码器－解码器”自注意力权重\n","            self._attention_weights[1][\n","                i] = blk.attention2.attention.attention_weights\n","        return self.dense(X), state\n","\n","    @property\n","    def attention_weights(self):\n","        return self._attention_weights"],"id":"d19ed317"},{"cell_type":"markdown","metadata":{"origin_pos":52,"id":"15de28d7"},"source":["## [**训练**]\n","\n","依照transformer架构来实例化编码器－解码器模型。在这里，指定transformer的编码器和解码器都是2层，都使用4头注意力。与 :numref:`sec_seq2seq_training`类似，为了进行序列到序列的学习，我们在“英语－法语”机器翻译数据集上训练transformer模型。\n"],"id":"15de28d7"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:01:53.288973Z","iopub.status.busy":"2022-07-31T03:01:53.288504Z","iopub.status.idle":"2022-07-31T03:03:11.619636Z","shell.execute_reply":"2022-07-31T03:03:11.618932Z"},"origin_pos":54,"tab":["pytorch"],"id":"c359c479","outputId":"a7d457db-97fb-4b00-86b4-d50cb3b15e08"},"outputs":[{"name":"stdout","output_type":"stream","text":["loss 0.033, 5993.4 tokens/sec on cuda:0\n"]},{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"262.1875pt\" height=\"180.65625pt\" viewBox=\"0 0 262.1875 180.65625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T03:03:11.591237</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 180.65625 \n","L 262.1875 180.65625 \n","L 262.1875 0 \n","L 0 0 \n","L 0 180.65625 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 50.14375 143.1 \n","L 245.44375 143.1 \n","L 245.44375 7.2 \n","L 50.14375 7.2 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <path d=\"M 91.259539 143.1 \n","L 91.259539 7.2 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_2\">\n","      <defs>\n","       <path id=\"m94be8ca54b\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m94be8ca54b\" x=\"91.259539\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 50 -->\n","      <g transform=\"translate(84.897039 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_3\">\n","      <path d=\"M 142.654276 143.1 \n","L 142.654276 7.2 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m94be8ca54b\" x=\"142.654276\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 100 -->\n","      <g transform=\"translate(133.110526 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <path d=\"M 194.049013 143.1 \n","L 194.049013 7.2 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m94be8ca54b\" x=\"194.049013\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 150 -->\n","      <g transform=\"translate(184.505263 157.698438)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <path d=\"M 245.44375 143.1 \n","L 245.44375 7.2 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m94be8ca54b\" x=\"245.44375\" y=\"143.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_4\">\n","      <!-- 200 -->\n","      <g transform=\"translate(235.9 157.698438)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_5\">\n","     <!-- epoch -->\n","     <g transform=\"translate(132.565625 171.376563)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \n","L 3122 2828 \n","Q 2878 2963 2633 3030 \n","Q 2388 3097 2138 3097 \n","Q 1578 3097 1268 2742 \n","Q 959 2388 959 1747 \n","Q 959 1106 1268 751 \n","Q 1578 397 2138 397 \n","Q 2388 397 2633 464 \n","Q 2878 531 3122 666 \n","L 3122 134 \n","Q 2881 22 2623 -34 \n","Q 2366 -91 2075 -91 \n","Q 1284 -91 818 406 \n","Q 353 903 353 1747 \n","Q 353 2603 823 3093 \n","Q 1294 3584 2113 3584 \n","Q 2378 3584 2631 3529 \n","Q 2884 3475 3122 3366 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 4863 \n","L 1159 4863 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-65\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"61.523438\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"125\"/>\n","      <use xlink:href=\"#DejaVuSans-63\" x=\"186.181641\"/>\n","      <use xlink:href=\"#DejaVuSans-68\" x=\"241.162109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_9\">\n","      <path d=\"M 50.14375 122.920438 \n","L 245.44375 122.920438 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_10\">\n","      <defs>\n","       <path id=\"mb3e56ad0d6\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mb3e56ad0d6\" x=\"50.14375\" y=\"122.920438\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_6\">\n","      <!-- 0.05 -->\n","      <g transform=\"translate(20.878125 126.719657)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_11\">\n","      <path d=\"M 50.14375 82.899077 \n","L 245.44375 82.899077 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#mb3e56ad0d6\" x=\"50.14375\" y=\"82.899077\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_7\">\n","      <!-- 0.10 -->\n","      <g transform=\"translate(20.878125 86.698296)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_13\">\n","      <path d=\"M 50.14375 42.877716 \n","L 245.44375 42.877716 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n","     </g>\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#mb3e56ad0d6\" x=\"50.14375\" y=\"42.877716\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0.15 -->\n","      <g transform=\"translate(20.878125 46.676935)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-31\" x=\"95.410156\"/>\n","       <use xlink:href=\"#DejaVuSans-35\" x=\"159.033203\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_9\">\n","     <!-- loss -->\n","     <g transform=\"translate(14.798437 84.807812)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n","L 1178 4863 \n","L 1178 0 \n","L 603 0 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-6c\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"27.783203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"88.964844\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"141.064453\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"line2d_15\">\n","    <path d=\"M 50.14375 13.377273 \n","L 60.422697 53.275903 \n","L 70.701645 78.408068 \n","L 80.980592 96.540534 \n","L 91.259539 108.261357 \n","L 101.538487 117.812312 \n","L 111.817434 121.228272 \n","L 122.096382 124.658113 \n","L 132.375329 128.607673 \n","L 142.654276 130.439949 \n","L 152.933224 131.310017 \n","L 163.212171 129.96903 \n","L 173.491118 133.569781 \n","L 183.770066 134.406083 \n","L 194.049013 135.016495 \n","L 204.327961 134.438805 \n","L 214.606908 135.401129 \n","L 224.885855 136.866812 \n","L 235.164803 136.905164 \n","L 245.44375 136.922727 \n","\" clip-path=\"url(#p26f3c8e97c)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 50.14375 143.1 \n","L 50.14375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 245.44375 143.1 \n","L 245.44375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 50.14375 143.1 \n","L 245.44375 143.1 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 50.14375 7.2 \n","L 245.44375 7.2 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p26f3c8e97c\">\n","   <rect x=\"50.14375\" y=\"7.2\" width=\"195.3\" height=\"135.9\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 252x180 with 1 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["num_hiddens, num_layers, dropout, batch_size, num_steps = 32, 2, 0.1, 64, 10\n","lr, num_epochs, device = 0.005, 200, d2l.try_gpu()\n","ffn_num_input, ffn_num_hiddens, num_heads = 32, 64, 4\n","key_size, query_size, value_size = 32, 32, 32\n","norm_shape = [32]\n","\n","train_iter, src_vocab, tgt_vocab = d2l.load_data_nmt(batch_size, num_steps)\n","\n","encoder = TransformerEncoder(\n","    len(src_vocab), key_size, query_size, value_size, num_hiddens,\n","    norm_shape, ffn_num_input, ffn_num_hiddens, num_heads,\n","    num_layers, dropout)\n","decoder = TransformerDecoder(\n","    len(tgt_vocab), key_size, query_size, value_size, num_hiddens,\n","    norm_shape, ffn_num_input, ffn_num_hiddens, num_heads,\n","    num_layers, dropout)\n","net = d2l.EncoderDecoder(encoder, decoder)\n","d2l.train_seq2seq(net, train_iter, lr, num_epochs, tgt_vocab, device)"],"id":"c359c479"},{"cell_type":"markdown","metadata":{"origin_pos":56,"id":"5b0f2523"},"source":["训练结束后，使用transformer模型[**将一些英语句子翻译成法语**]，并且计算它们的BLEU分数。\n"],"id":"5b0f2523"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:11.622906Z","iopub.status.busy":"2022-07-31T03:03:11.622407Z","iopub.status.idle":"2022-07-31T03:03:11.729508Z","shell.execute_reply":"2022-07-31T03:03:11.728795Z"},"origin_pos":57,"tab":["pytorch"],"id":"24013ec6","outputId":"312e2fba-39c7-466b-ae79-f70d3897930a"},"outputs":[{"name":"stdout","output_type":"stream","text":["go . => va !,  bleu 1.000\n","i lost . => je suis avons été battues .,  bleu 0.000\n","he's calm . => il est malade .,  bleu 0.658\n","i'm home . => je suis chez moi .,  bleu 1.000\n"]}],"source":["engs = ['go .', \"i lost .\", 'he\\'s calm .', 'i\\'m home .']\n","fras = ['va !', 'j\\'ai perdu .', 'il est calme .', 'je suis chez moi .']\n","for eng, fra in zip(engs, fras):\n","    translation, dec_attention_weight_seq = d2l.predict_seq2seq(\n","        net, eng, src_vocab, tgt_vocab, num_steps, device, True)\n","    print(f'{eng} => {translation}, ',\n","          f'bleu {d2l.bleu(translation, fra, k=2):.3f}')"],"id":"24013ec6"},{"cell_type":"markdown","metadata":{"origin_pos":59,"id":"3b144dab"},"source":["当进行最后一个英语到法语的句子翻译工作时，让我们[**可视化transformer的注意力权重**]。编码器自注意力权重的形状为（编码器层数，注意力头数，`num_steps`或查询的数目，`num_steps`或“键－值”对的数目）。\n"],"id":"3b144dab"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:11.732810Z","iopub.status.busy":"2022-07-31T03:03:11.732295Z","iopub.status.idle":"2022-07-31T03:03:11.738200Z","shell.execute_reply":"2022-07-31T03:03:11.737489Z"},"origin_pos":60,"tab":["pytorch"],"id":"78f1ea03","outputId":"c42a853c-e0bc-4d4b-cff5-97d47d8ca0f9"},"outputs":[{"data":{"text/plain":["torch.Size([2, 4, 10, 10])"]},"execution_count":16,"metadata":{},"output_type":"execute_result"}],"source":["enc_attention_weights = torch.cat(net.encoder.attention_weights, 0).reshape((num_layers, num_heads,\n","    -1, num_steps))\n","enc_attention_weights.shape"],"id":"78f1ea03"},{"cell_type":"markdown","metadata":{"origin_pos":61,"id":"897a596d"},"source":["在编码器的自注意力中，查询和键都来自相同的输入序列。因为填充词元是不携带信息的，因此通过指定输入序列的有效长度可以避免查询与使用填充词元的位置计算注意力。接下来，将逐行呈现两层多头注意力的权重。每个注意力头都根据查询、键和值的不同的表示子空间来表示不同的注意力。\n"],"id":"897a596d"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:11.741370Z","iopub.status.busy":"2022-07-31T03:03:11.740883Z","iopub.status.idle":"2022-07-31T03:03:12.519385Z","shell.execute_reply":"2022-07-31T03:03:12.518542Z"},"origin_pos":63,"tab":["pytorch"],"id":"0cae647a","outputId":"fcd94631-e996-407e-863e-3c538e39af61"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"402.06155pt\" height=\"231.582992pt\" viewBox=\"0 0 402.06155 231.582992\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T03:03:12.286677</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 231.582992 \n","L 402.06155 231.582992 \n","L 402.06155 0 \n","L 0 0 \n","L 0 231.582992 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 90.24856 \n","L 102.17106 90.24856 \n","L 102.17106 22.318125 \n","L 34.240625 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pb3d7f31717)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAzElEQVR4nO3buw3CMBRAUYcWRmA/GIkBGYAmdai5whQ0fHRO6TTW1ZMiWfZyGodtTFzW6+zT39p9egPfRpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJASJZVtv04u7r5z3x6frv37Z14SEICFICBKChCAhSAgSgoQgIUgIEotXmY9MSAgSgoQgIUgIEm+fqc7MzlrH+I3fuAkJQUKQECQECUHiDjwCFhF2A59xAAAAAElFTkSuQmCC\" id=\"image4c5eee392e\" transform=\"scale(1 -1)translate(0 -68)\" x=\"34.240625\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"mfcca9f7894\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"37.637147\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"71.602364\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"m8619afeea4\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"34.240625\" y=\"25.714647\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 29.513865)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"34.240625\" y=\"59.679864\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 5 -->\n","      <g transform=\"translate(20.878125 63.479083)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 95.477874)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 90.24856 \n","L 34.240625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 102.17106 90.24856 \n","L 102.17106 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 90.24856 \n","L 102.17106 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 22.318125 \n","L 102.17106 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_4\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-48\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2753 \n","L 3553 2753 \n","L 3553 4666 \n","L 4184 4666 \n","L 4184 0 \n","L 3553 0 \n","L 3553 2222 \n","L 1259 2222 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n","Q 1497 1759 1228 1600 \n","Q 959 1441 959 1056 \n","Q 959 750 1161 570 \n","Q 1363 391 1709 391 \n","Q 2188 391 2477 730 \n","Q 2766 1069 2766 1631 \n","L 2766 1759 \n","L 2194 1759 \n","z\n","M 3341 1997 \n","L 3341 0 \n","L 2766 0 \n","L 2766 531 \n","Q 2569 213 2275 61 \n","Q 1981 -91 1556 -91 \n","Q 1019 -91 701 211 \n","Q 384 513 384 1019 \n","Q 384 1609 779 1909 \n","Q 1175 2209 1959 2209 \n","L 2766 2209 \n","L 2766 2266 \n","Q 2766 2663 2505 2880 \n","Q 2244 3097 1772 3097 \n","Q 1472 3097 1187 3025 \n","Q 903 2953 641 2809 \n","L 641 3341 \n","Q 956 3463 1253 3523 \n","Q 1550 3584 1831 3584 \n","Q 2591 3584 2966 3190 \n","Q 3341 2797 3341 1997 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 115.757147 90.24856 \n","L 183.687582 90.24856 \n","L 183.687582 22.318125 \n","L 115.757147 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p86ad1ca572)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAyklEQVR4nO3csQ3CMBRAwQTRwQjsByMxIAPQpA41TzgtBN2VdmM9fcmN5fk6nddp4L48Rlt/6/DtA/waQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECTmdXkOH+5uuZ0uH9f3/tjXhIQgIUgIEoKEIHHc2hxdrdO0/+t1xISEICFICBKChCAhSAgSgoQgIUgIErPPEN6ZkBAkBAlBQpAQJF6qUxIxkx3lIQAAAABJRU5ErkJggg==\" id=\"image73247d976b\" transform=\"scale(1 -1)translate(0 -68)\" x=\"115.757147\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"119.153668\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"153.118886\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_4\">\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"115.757147\" y=\"25.714647\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"115.757147\" y=\"59.679864\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path d=\"M 115.757147 90.24856 \n","L 115.757147 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_9\">\n","    <path d=\"M 183.687582 90.24856 \n","L 183.687582 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_10\">\n","    <path d=\"M 115.757147 90.24856 \n","L 183.687582 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_11\">\n","    <path d=\"M 115.757147 22.318125 \n","L 183.687582 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_5\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_3\">\n","   <g id=\"patch_12\">\n","    <path d=\"M 197.273668 90.24856 \n","L 265.204103 90.24856 \n","L 265.204103 22.318125 \n","L 197.273668 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p7d39bbe400)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAzklEQVR4nO3bsQ3CQBAAQRuRQQn0ByVRIAWQODb5indAAkYzoT+xViedPvj5Op3XaeC+PEZHf+vw7R/4NYKEICFICBKChCAhSAgSgoQgIUgIEoKEICFICBKChCAhSAgSgoQgIUgIEoKEICFICBKChCAhSAgSgoQgIUgIEoKEICFICBKChCAhSAgSgoQgMa/Lc/heZsvtdHn7fe9vbExICBKChCAhSBy3DkebZJr2v01GTEgIEoKEICFICBIfX+5G9r6qTUgIEoKEICFICBIvdpoVMYOxMjgAAAAASUVORK5CYII=\" id=\"imagecbd1c0c7b1\" transform=\"scale(1 -1)translate(0 -68)\" x=\"197.273668\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_5\">\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"200.67019\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"234.635408\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_6\">\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"197.273668\" y=\"25.714647\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"197.273668\" y=\"59.679864\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_13\">\n","    <path d=\"M 197.273668 90.24856 \n","L 197.273668 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_14\">\n","    <path d=\"M 265.204103 90.24856 \n","L 265.204103 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_15\">\n","    <path d=\"M 197.273668 90.24856 \n","L 265.204103 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_16\">\n","    <path d=\"M 197.273668 22.318125 \n","L 265.204103 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_6\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_4\">\n","   <g id=\"patch_17\">\n","    <path d=\"M 278.79019 90.24856 \n","L 346.720625 90.24856 \n","L 346.720625 22.318125 \n","L 278.79019 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p32477087df)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAwklEQVR4nO3bsQ3CMBBA0ZgWRmA/GIkBGYAmdaj5Co0bgvRe6cKyvq5xcWNbX9sy4X6+7p4/1ufMdYdx+vUDjkaQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJMZtuXzdl/n33ZcZJiQECUFCkBAkhq3MTyYkBAlBQpAQJAQJn7swISFICBKChCAhSLwBKQsWEdzHgUMAAAAASUVORK5CYII=\" id=\"imagec0da1acc6a\" transform=\"scale(1 -1)translate(0 -68)\" x=\"278.79019\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_7\">\n","    <g id=\"xtick_7\">\n","     <g id=\"line2d_13\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"282.186712\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_8\">\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"316.151929\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_8\">\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_15\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"278.79019\" y=\"25.714647\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"278.79019\" y=\"59.679864\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_18\">\n","    <path d=\"M 278.79019 90.24856 \n","L 278.79019 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_19\">\n","    <path d=\"M 346.720625 90.24856 \n","L 346.720625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_20\">\n","    <path d=\"M 278.79019 90.24856 \n","L 346.720625 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_21\">\n","    <path d=\"M 278.79019 22.318125 \n","L 346.720625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_7\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_5\">\n","   <g id=\"patch_22\">\n","    <path d=\"M 34.240625 194.026742 \n","L 102.17106 194.026742 \n","L 102.17106 126.096307 \n","L 34.240625 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pf88bb2bf9e)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABhElEQVR4nO3aQUoDMRiG4WRMacGVC3Enit5CcOtRxB7AG4jeQLeeQOgBXHgGFx5AqIuKVC0KnUncf+QPRSwzI++zTPhLeAkMw9Q3jw/JGeLdrbXl3HSaXd44vzJH/Pau/XsdUbV9gK4hiCCIIIggiCCICMXdGO0977PLKZlPcZef6BZuiCCIIIggiCCIIIgILhUerU1j7w2H+fVYmOkBboggiCCIIIggiAjFJ0nhRc0NBn9/mg7ghgiCCIIIggiCCIKIUHy0/obvd+N+n34NCCIIIggiCCIIIsqfMo3Plc455+o6P1L1u3G/T78GBBEEEQQRBBEEET6+vZivu2dbh+bg9etTdj3NZ+ZMtbO3+slawg0RBBEEEQQRBBEEEcF9fZibB6PC99t6mV3mbfefIYggiCCIIIjwy8tT8+XOH5/Yk6PN7HK6n5gjYXyx+slawg0RBBEEEQQRBBEEET6+z+y/EH1/mltpMc+uj/ePzJmbxfPqJ2sJN0QQRBBEEEQQRBBE/AAM1j0xlVs7NgAAAABJRU5ErkJggg==\" id=\"imagef54398c304\" transform=\"scale(1 -1)translate(0 -68)\" x=\"34.240625\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_9\">\n","    <g id=\"xtick_9\">\n","     <g id=\"line2d_17\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"37.637147\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0 -->\n","      <g transform=\"translate(34.455897 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_10\">\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"71.602364\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 5 -->\n","      <g transform=\"translate(68.421114 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(35.142561 222.303304)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_10\">\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_19\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"34.240625\" y=\"129.492829\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 133.292047)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_10\">\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"34.240625\" y=\"163.458046\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 5 -->\n","      <g transform=\"translate(20.878125 167.257265)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_13\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 199.256055)rotate(-90)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_23\">\n","    <path d=\"M 34.240625 194.026742 \n","L 34.240625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_24\">\n","    <path d=\"M 102.17106 194.026742 \n","L 102.17106 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_25\">\n","    <path d=\"M 34.240625 194.026742 \n","L 102.17106 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_26\">\n","    <path d=\"M 34.240625 126.096307 \n","L 102.17106 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_14\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_6\">\n","   <g id=\"patch_27\">\n","    <path d=\"M 115.757147 194.026742 \n","L 183.687582 194.026742 \n","L 183.687582 126.096307 \n","L 115.757147 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p2c391ac2c8)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABeElEQVR4nO3Zv0rDUBhA8dwmxUHFxUnwD7j5CgXRoYvP4OAkuPkYvoGLm7uLa30KBzcHV3GQKii0ifshXyhRTKvnN+bjlsvhwiVpGq1vVFngcHQdjbK0vRcMevGa/lI4mxfx7v8pg4BBwCBgEDAIFFUW3rrtpPSzv/fLPCFgEDAIGAQMAgaBIs8arsmqxZXcZs0c8YSAQcAgYBAwCBR5w8tYVU7DWYpuk8V+t/OEkEHAIGAQMAgYBIp+0zfQaXzthi9xvtz9LQYBg4BBwCBgECjKpr8yew1X8oL/ZRnxhIBBwCBgEDAIGARS+foc37uTz3D0ODiofb5zcR6uyYfHs+6rM54QMAgYBAwCBgGDQJF9vMfTPA9HW/u7tc+rh/v494azbqs7nhAwCBgEDAIGgSJbXguHZyub4exy/FQ/KCff3VOnPCFgEDAIGAQMAgaBVI5fwm+q5e1VuLA3OKp9/nZ6Eq5ZvbmbfWcd8YSAQcAgYBAwCBgEvgA2/DSt7TSSPQAAAABJRU5ErkJggg==\" id=\"imagee062522ed2\" transform=\"scale(1 -1)translate(0 -68)\" x=\"115.757147\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_11\">\n","    <g id=\"xtick_11\">\n","     <g id=\"line2d_21\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"119.153668\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_15\">\n","      <!-- 0 -->\n","      <g transform=\"translate(115.972418 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_12\">\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"153.118886\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_16\">\n","      <!-- 5 -->\n","      <g transform=\"translate(149.937636 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(116.659083 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_12\">\n","    <g id=\"ytick_11\">\n","     <g id=\"line2d_23\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"115.757147\" y=\"129.492829\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_12\">\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"115.757147\" y=\"163.458046\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_28\">\n","    <path d=\"M 115.757147 194.026742 \n","L 115.757147 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_29\">\n","    <path d=\"M 183.687582 194.026742 \n","L 183.687582 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_30\">\n","    <path d=\"M 115.757147 194.026742 \n","L 183.687582 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_31\">\n","    <path d=\"M 115.757147 126.096307 \n","L 183.687582 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_18\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_7\">\n","   <g id=\"patch_32\">\n","    <path d=\"M 197.273668 194.026742 \n","L 265.204103 194.026742 \n","L 265.204103 126.096307 \n","L 197.273668 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p2d6500c2bf)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABTElEQVR4nO3aPUoEQRBA4W5pVIx0A0FzPYCRqUcy8BLexCt4AhMPYGRiJBr4AyuC0+YPq1gXdHb0fWkxy/AoaHp36/B030vg6uAoGpXj68twFqmz/W8/89vWxn6BVWMQMAgYBAwCBoFWSg2HvYQnciL+vClwQ8AgYBAwCBgEDAItG+aH7rSP14gbAgYBg4BBwCDQsrPkIztmqqfMv2AQMAgYBAwCBoH0cjdk17satVzme9jV4YaAQcAgYBAwCBgE8u9Up32CLsUNAYOAQcAgYBAwCLTa1sPhxcNzODvZ3v2J9xmdGwIGAYOAQcAgYBBofRjCYf2j/xLKuCFgEDAIGAQMAq3f3YTD08P4AtfnL18P5q/hM3W2t/CLjcUNAYOAQcAgYBAwCNTzzZ3wB8uzx9vwwf7+FgySy+LG1uJvNhI3BAwCBgGDgEHAIPAJUvAptsk0wOAAAAAASUVORK5CYII=\" id=\"image23028a97d3\" transform=\"scale(1 -1)translate(0 -68)\" x=\"197.273668\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_13\">\n","    <g id=\"xtick_13\">\n","     <g id=\"line2d_25\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"200.67019\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_19\">\n","      <!-- 0 -->\n","      <g transform=\"translate(197.48894 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_14\">\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"234.635408\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_20\">\n","      <!-- 5 -->\n","      <g transform=\"translate(231.454158 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_21\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(198.175605 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_14\">\n","    <g id=\"ytick_13\">\n","     <g id=\"line2d_27\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"197.273668\" y=\"129.492829\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_14\">\n","     <g id=\"line2d_28\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"197.273668\" y=\"163.458046\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_33\">\n","    <path d=\"M 197.273668 194.026742 \n","L 197.273668 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_34\">\n","    <path d=\"M 265.204103 194.026742 \n","L 265.204103 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_35\">\n","    <path d=\"M 197.273668 194.026742 \n","L 265.204103 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_36\">\n","    <path d=\"M 197.273668 126.096307 \n","L 265.204103 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_22\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_8\">\n","   <g id=\"patch_37\">\n","    <path d=\"M 278.79019 194.026742 \n","L 346.720625 194.026742 \n","L 346.720625 126.096307 \n","L 278.79019 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p74a58419b3)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABUUlEQVR4nO3cMUoDQRhA4Zl1EBFyBUGwEzt7z+EN9ELiDXICq3Q5gXgAUbATbIKNhBn7h/+AgZCMvq/9mWV5DAy7WZLr+2tLgfnZZTRK18+PPw+mg3BNPjwKZ/ti2vUN7BuDgEHAIGAQMAiUlOMm6xaeyH+WOwQMAgYBg4BBwCBQUs7h8Kt2jt1oXed6I3CHgEHAIGAQMAiU3nDde7bzlPkfDAIGAYOAQcAgUFLnvenUPUHHPl4j7hAwCBgEDAIGAYNASa3Gw02eXAf/+dMdAgYBg4BBwCBgECj1aRkOz4/jD22jj3BbjY/xEbhDwCBgEDAIGAQMAqUtHsLhxdXpry+Yp7Ebj333W2AQMAgYBAwCua4+wpegt7OTcOH959tWbmjX3CFgEDAIGAQMAgaBfJNm4bF7t3qJFwZ/etA6P2XmAT7qdYeAQcAgYBAwCBgEvgGSPiwT/whphwAAAABJRU5ErkJggg==\" id=\"imageddf7eaca09\" transform=\"scale(1 -1)translate(0 -68)\" x=\"278.79019\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_15\">\n","    <g id=\"xtick_15\">\n","     <g id=\"line2d_29\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"282.186712\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_23\">\n","      <!-- 0 -->\n","      <g transform=\"translate(279.005462 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_16\">\n","     <g id=\"line2d_30\">\n","      <g>\n","       <use xlink:href=\"#mfcca9f7894\" x=\"316.151929\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_24\">\n","      <!-- 5 -->\n","      <g transform=\"translate(312.970679 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_25\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(279.692126 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_16\">\n","    <g id=\"ytick_15\">\n","     <g id=\"line2d_31\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"278.79019\" y=\"129.492829\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_16\">\n","     <g id=\"line2d_32\">\n","      <g>\n","       <use xlink:href=\"#m8619afeea4\" x=\"278.79019\" y=\"163.458046\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_38\">\n","    <path d=\"M 278.79019 194.026742 \n","L 278.79019 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_39\">\n","    <path d=\"M 346.720625 194.026742 \n","L 346.720625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_40\">\n","    <path d=\"M 278.79019 194.026742 \n","L 346.720625 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_41\">\n","    <path d=\"M 278.79019 126.096307 \n","L 346.720625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_26\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_9\">\n","   <g id=\"patch_42\">\n","    <path d=\"M 366.250625 165.250433 \n","L 371.958425 165.250433 \n","L 371.958425 51.094433 \n","L 366.250625 51.094433 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_43\">\n","    <path clip-path=\"url(#p73ede41224)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAYAAAByCAYAAABwf6CfAAAAzElEQVR4nLXWQQ7DIBBDUSpx/7N2001hhl6AF2kQzTKW/fGQkLzW573a5upt5e5+6y0pBIS1RZwwlhmKqgtkZLkHhZgSCIfgkZhxDW5hjr3g5boHBTAOetAxNat6lGd1bz/cQ7M66KGH+qAH34/6fujIuAivCwcF9Z4HC5IBIcWgow5f89pyzRg8E6tRGTjbQ0LqaxAS6gxHlRmTzeuMfdJTD/0BpAQktZ5NBc1AVCiKDjP2hqeCcnBWFhTF5Q7tIB2zPJLvvSg6xv8ZP9W5DE4Qbu8+AAAAAElFTkSuQmCC\" id=\"image5e05ba8322\" transform=\"scale(1 -1)translate(0 -114)\" x=\"366\" y=\"-51\" width=\"6\" height=\"114\"/>\n","   <g id=\"matplotlib.axis_17\">\n","    <g id=\"ytick_17\">\n","     <g id=\"line2d_33\">\n","      <defs>\n","       <path id=\"mf43df6f72c\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mf43df6f72c\" x=\"371.958425\" y=\"165.250433\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_27\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(378.958425 169.049652)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_18\">\n","     <g id=\"line2d_34\">\n","      <g>\n","       <use xlink:href=\"#mf43df6f72c\" x=\"371.958425\" y=\"142.171331\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_28\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(378.958425 145.97055)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_19\">\n","     <g id=\"line2d_35\">\n","      <g>\n","       <use xlink:href=\"#mf43df6f72c\" x=\"371.958425\" y=\"119.092229\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_29\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(378.958425 122.891448)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_20\">\n","     <g id=\"line2d_36\">\n","      <g>\n","       <use xlink:href=\"#mf43df6f72c\" x=\"371.958425\" y=\"96.013127\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_30\">\n","      <!-- 0.6 -->\n","      <g transform=\"translate(378.958425 99.812346)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-36\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_21\">\n","     <g id=\"line2d_37\">\n","      <g>\n","       <use xlink:href=\"#mf43df6f72c\" x=\"371.958425\" y=\"72.934025\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_31\">\n","      <!-- 0.8 -->\n","      <g transform=\"translate(378.958425 76.733243)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n","Q 1584 2216 1326 1975 \n","Q 1069 1734 1069 1313 \n","Q 1069 891 1326 650 \n","Q 1584 409 2034 409 \n","Q 2484 409 2743 651 \n","Q 3003 894 3003 1313 \n","Q 3003 1734 2745 1975 \n","Q 2488 2216 2034 2216 \n","z\n","M 1403 2484 \n","Q 997 2584 770 2862 \n","Q 544 3141 544 3541 \n","Q 544 4100 942 4425 \n","Q 1341 4750 2034 4750 \n","Q 2731 4750 3128 4425 \n","Q 3525 4100 3525 3541 \n","Q 3525 3141 3298 2862 \n","Q 3072 2584 2669 2484 \n","Q 3125 2378 3379 2068 \n","Q 3634 1759 3634 1313 \n","Q 3634 634 3220 271 \n","Q 2806 -91 2034 -91 \n","Q 1263 -91 848 271 \n","Q 434 634 434 1313 \n","Q 434 1759 690 2068 \n","Q 947 2378 1403 2484 \n","z\n","M 1172 3481 \n","Q 1172 3119 1398 2916 \n","Q 1625 2713 2034 2713 \n","Q 2441 2713 2670 2916 \n","Q 2900 3119 2900 3481 \n","Q 2900 3844 2670 4047 \n","Q 2441 4250 2034 4250 \n","Q 1625 4250 1398 4047 \n","Q 1172 3844 1172 3481 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-38\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_44\">\n","    <path d=\"M 366.250625 165.250433 \n","L 369.104525 165.250433 \n","L 371.958425 165.250433 \n","L 371.958425 51.094433 \n","L 369.104525 51.094433 \n","L 366.250625 51.094433 \n","L 366.250625 165.250433 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"pb3d7f31717\">\n","   <rect x=\"34.240625\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p86ad1ca572\">\n","   <rect x=\"115.757147\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p7d39bbe400\">\n","   <rect x=\"197.273668\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p32477087df\">\n","   <rect x=\"278.79019\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pf88bb2bf9e\">\n","   <rect x=\"34.240625\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p2c391ac2c8\">\n","   <rect x=\"115.757147\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p2d6500c2bf\">\n","   <rect x=\"197.273668\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p74a58419b3\">\n","   <rect x=\"278.79019\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p73ede41224\">\n","   <rect x=\"366.250625\" y=\"51.094433\" width=\"5.7078\" height=\"114.156\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 504x252 with 9 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(\n","    enc_attention_weights.cpu(), xlabel='Key positions',\n","    ylabel='Query positions', titles=['Head %d' % i for i in range(1, 5)],\n","    figsize=(7, 3.5))"],"id":"0cae647a"},{"cell_type":"markdown","metadata":{"origin_pos":64,"id":"ad642644"},"source":["[**为了可视化解码器的自注意力权重和“编码器－解码器”的注意力权重，我们需要完成更多的数据操作工作。**]例如，我们用零填充被掩蔽住的注意力权重。值得注意的是，解码器的自注意力权重和“编码器－解码器”的注意力权重都有相同的查询：即以*序列开始词元*（beginning-of-sequence,BOS）打头，再与后续输出的词元共同组成序列。\n"],"id":"ad642644"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:12.522884Z","iopub.status.busy":"2022-07-31T03:03:12.522171Z","iopub.status.idle":"2022-07-31T03:03:12.535162Z","shell.execute_reply":"2022-07-31T03:03:12.534265Z"},"origin_pos":66,"tab":["pytorch"],"id":"a18c2770","outputId":"2ddd1dba-33b4-4aa6-bd16-efbdad5bdd8c"},"outputs":[{"data":{"text/plain":["(torch.Size([2, 4, 6, 10]), torch.Size([2, 4, 6, 10]))"]},"execution_count":18,"metadata":{},"output_type":"execute_result"}],"source":["dec_attention_weights_2d = [head[0].tolist()\n","                            for step in dec_attention_weight_seq\n","                            for attn in step for blk in attn for head in blk]\n","dec_attention_weights_filled = torch.tensor(\n","    pd.DataFrame(dec_attention_weights_2d).fillna(0.0).values)\n","dec_attention_weights = dec_attention_weights_filled.reshape((-1, 2, num_layers, num_heads, num_steps))\n","dec_self_attention_weights, dec_inter_attention_weights = \\\n","    dec_attention_weights.permute(1, 2, 3, 0, 4)\n","dec_self_attention_weights.shape, dec_inter_attention_weights.shape"],"id":"a18c2770"},{"cell_type":"markdown","metadata":{"origin_pos":68,"id":"cb303a45"},"source":["由于解码器自注意力的自回归属性，查询不会对当前位置之后的“键－值”对进行注意力计算。\n"],"id":"cb303a45"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:12.539466Z","iopub.status.busy":"2022-07-31T03:03:12.538760Z","iopub.status.idle":"2022-07-31T03:03:13.233536Z","shell.execute_reply":"2022-07-31T03:03:13.232656Z"},"origin_pos":69,"tab":["pytorch"],"id":"065c21cf","outputId":"8bb2877e-835a-46f4-f166-83e1cc370686"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"402.06155pt\" height=\"231.582992pt\" viewBox=\"0 0 402.06155 231.582992\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T03:03:13.080080</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 231.582992 \n","L 402.06155 231.582992 \n","L 402.06155 0 \n","L 0 0 \n","L 0 231.582992 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 90.24856 \n","L 102.17106 90.24856 \n","L 102.17106 22.318125 \n","L 34.240625 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p589e8b64e0)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAA2UlEQVR4nO3asY0CMRRAQS8i40qgPyiJAimAhJjLX7RGWrGgmdiB9fQDW/byej5e48ddT+fVaw8b7uMrCRKChCAhSAgSgoQgIUgIEsdPb+AdM0fxMca4Pe+r15qQECQECUFCkBAkBAlBQpAQJASJ3dxlZu4nM3eTWSYkBAlBQpAQJAQJQUKQECQEieUy/lb/INryyLwXJiQECUFCkBAkBAlBQpAQJASJZebz/5Y/d/bChIQgIUgIEoKEICFICBKChCAhSHiGCBMSgoQgIUgIEoKEICFICBKCxD9VYRmkiSaakAAAAABJRU5ErkJggg==\" id=\"image865f19c8d4\" transform=\"scale(1 -1)translate(0 -68)\" x=\"34.240625\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"mc639b42e72\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"39.901495\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"96.51019\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"mdd65203fa5\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"27.978995\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 31.778213)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"50.622473\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 2 -->\n","      <g transform=\"translate(20.878125 54.421692)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"73.265951\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_3\">\n","      <!-- 4 -->\n","      <g transform=\"translate(20.878125 77.06517)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_4\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 95.477874)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 90.24856 \n","L 34.240625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 102.17106 90.24856 \n","L 102.17106 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 90.24856 \n","L 102.17106 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 22.318125 \n","L 102.17106 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_5\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-48\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2753 \n","L 3553 2753 \n","L 3553 4666 \n","L 4184 4666 \n","L 4184 0 \n","L 3553 0 \n","L 3553 2222 \n","L 1259 2222 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n","Q 1497 1759 1228 1600 \n","Q 959 1441 959 1056 \n","Q 959 750 1161 570 \n","Q 1363 391 1709 391 \n","Q 2188 391 2477 730 \n","Q 2766 1069 2766 1631 \n","L 2766 1759 \n","L 2194 1759 \n","z\n","M 3341 1997 \n","L 3341 0 \n","L 2766 0 \n","L 2766 531 \n","Q 2569 213 2275 61 \n","Q 1981 -91 1556 -91 \n","Q 1019 -91 701 211 \n","Q 384 513 384 1019 \n","Q 384 1609 779 1909 \n","Q 1175 2209 1959 2209 \n","L 2766 2209 \n","L 2766 2266 \n","Q 2766 2663 2505 2880 \n","Q 2244 3097 1772 3097 \n","Q 1472 3097 1187 3025 \n","Q 903 2953 641 2809 \n","L 641 3341 \n","Q 956 3463 1253 3523 \n","Q 1550 3584 1831 3584 \n","Q 2591 3584 2966 3190 \n","Q 3341 2797 3341 1997 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 115.757147 90.24856 \n","L 183.687582 90.24856 \n","L 183.687582 22.318125 \n","L 115.757147 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p43a16bca14)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAyklEQVR4nO3asQ3CMBBAUYcWRmA/GIkBGYAmdaj5lVORSO/VLqKvKyKfl8e4bWPSa33PHj2ty78/4GgECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJASJZVs/02uIvZ7X+/TZo6w4TEgIEoKEICFICBKChCAhSAgSixdEv0xICBKChCAhSAgSgoQgIUgIErtu3ffcoo9xzl99ExKChCAhSAgSgoQgIUgIEoKEIGENESYkBAlBQpAQJAQJQUKQECQEiS8XshnzU5+4YAAAAABJRU5ErkJggg==\" id=\"image1f483b51ff\" transform=\"scale(1 -1)translate(0 -68)\" x=\"115.757147\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"121.418016\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"178.026712\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_4\">\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"27.978995\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_9\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"50.622473\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"73.265951\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path d=\"M 115.757147 90.24856 \n","L 115.757147 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_9\">\n","    <path d=\"M 183.687582 90.24856 \n","L 183.687582 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_10\">\n","    <path d=\"M 115.757147 90.24856 \n","L 183.687582 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_11\">\n","    <path d=\"M 115.757147 22.318125 \n","L 183.687582 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_6\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 16.318125)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_3\">\n","   <g id=\"patch_12\">\n","    <path d=\"M 197.273668 90.24856 \n","L 265.204103 90.24856 \n","L 265.204103 22.318125 \n","L 197.273668 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p96774354a8)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAxUlEQVR4nO3bMQ6CQBBA0V1bPYL30yN5QA9gQ439q6AgEfNfTTH5mQJ2w1yXzzr+3PN63/zs5cA5TqkgKAgKgoKgICgICoKCoCCYj3Hb/Or+Wt5HzvIT2hAUBAVBQVAQFAQFQUFQEBQEBcHccw2x5zh/jHN++7QhKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCDobwi0ISgICoKCoCAoCAqCgqAgKAi+fO0ToPrrPfEAAAAASUVORK5CYII=\" id=\"image3cccb5d841\" transform=\"scale(1 -1)translate(0 -68)\" x=\"197.273668\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_5\">\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"202.934538\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"259.543234\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_6\">\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_13\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"27.978995\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"50.622473\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_15\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"73.265951\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_13\">\n","    <path d=\"M 197.273668 90.24856 \n","L 197.273668 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_14\">\n","    <path d=\"M 265.204103 90.24856 \n","L 265.204103 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_15\">\n","    <path d=\"M 197.273668 90.24856 \n","L 265.204103 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_16\">\n","    <path d=\"M 197.273668 22.318125 \n","L 265.204103 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_7\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 16.318125)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_4\">\n","   <g id=\"patch_17\">\n","    <path d=\"M 278.79019 90.24856 \n","L 346.720625 90.24856 \n","L 346.720625 22.318125 \n","L 278.79019 22.318125 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pac315db926)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAAv0lEQVR4nO3ZsQ3CMBBA0ZiWjMB+MBIDMkCa1KHmV24iQHqvvsL6usKWx31Zj2XSc3/Njv6ty7cP8GsECUFCkBAkBAlBQpAQJASJcezb9NX9TI/rbXr2zCeEDQlBQpAQJAQJQUKQECQECUFCkBi+IT7ZkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQeINT/IPL7rQWxQAAAAASUVORK5CYII=\" id=\"imageccac1dae35\" transform=\"scale(1 -1)translate(0 -68)\" x=\"278.79019\" y=\"-22.24856\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_7\">\n","    <g id=\"xtick_7\">\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"284.45106\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_8\">\n","     <g id=\"line2d_17\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"341.059755\" y=\"90.24856\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_8\">\n","    <g id=\"ytick_10\">\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"27.978995\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_11\">\n","     <g id=\"line2d_19\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"50.622473\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_12\">\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"73.265951\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_18\">\n","    <path d=\"M 278.79019 90.24856 \n","L 278.79019 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_19\">\n","    <path d=\"M 346.720625 90.24856 \n","L 346.720625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_20\">\n","    <path d=\"M 278.79019 90.24856 \n","L 346.720625 90.24856 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_21\">\n","    <path d=\"M 278.79019 22.318125 \n","L 346.720625 22.318125 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_8\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 16.318125)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_5\">\n","   <g id=\"patch_22\">\n","    <path d=\"M 34.240625 194.026742 \n","L 102.17106 194.026742 \n","L 102.17106 126.096307 \n","L 34.240625 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pe2f387b989)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABPUlEQVR4nO3ZMUoDURCA4Xm6CEGLkMJWWxE8gHfwBJ7BIjeIB8g1BO/gPQQbU9goggrBBBey6f9qpggo/l89DI+fV7xlWz+/GSJp/3qaHY2IiOH9JT3bTs7Ts5uHu9I59i6v8rOlzf+AQcAgYBAwCBgEDAIGAYOAQaBtlh/pp3trrbR8+FmlZ2fHZ+nZ289F6RwV3hAwCBgEDAIGAYOAQcAgYBAwCBgEuvj+Sg8PB6PS8vvTi/Ts7O2xtHtXvCFgEDAIGAQMAgYBg4BBwCBgEGjz0ST9G2L6+lTbvl7mD3I4ru3eEW8IGAQMAgYBg4BBwCBgEDAIGAS6fki/3CNW+ad4REQ7GtdO8wt4Q8AgYBAwCBgEDAIGAYOAQcAgYBDontd9evgvfptUeUPAIGAQMAgYBAwCBgGDgEHAILAFzhYoNeYcZ5oAAAAASUVORK5CYII=\" id=\"image20cc2eebbd\" transform=\"scale(1 -1)translate(0 -68)\" x=\"34.240625\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_9\">\n","    <g id=\"xtick_9\">\n","     <g id=\"line2d_21\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"39.901495\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 0 -->\n","      <g transform=\"translate(36.720245 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_10\">\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"96.51019\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_10\">\n","      <!-- 5 -->\n","      <g transform=\"translate(93.32894 208.625179)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_11\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(35.142561 222.303304)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_10\">\n","    <g id=\"ytick_13\">\n","     <g id=\"line2d_23\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"131.757176\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 135.556395)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_14\">\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"154.400655\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_13\">\n","      <!-- 2 -->\n","      <g transform=\"translate(20.878125 158.199873)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-32\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_15\">\n","     <g id=\"line2d_25\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"34.240625\" y=\"177.044133\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_14\">\n","      <!-- 4 -->\n","      <g transform=\"translate(20.878125 180.843352)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-34\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_15\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 199.256055)rotate(-90)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_23\">\n","    <path d=\"M 34.240625 194.026742 \n","L 34.240625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_24\">\n","    <path d=\"M 102.17106 194.026742 \n","L 102.17106 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_25\">\n","    <path d=\"M 34.240625 194.026742 \n","L 102.17106 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_26\">\n","    <path d=\"M 34.240625 126.096307 \n","L 102.17106 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_16\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_6\">\n","   <g id=\"patch_27\">\n","    <path d=\"M 115.757147 194.026742 \n","L 183.687582 194.026742 \n","L 183.687582 126.096307 \n","L 115.757147 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p97e481024a)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABL0lEQVR4nO3aMWoCQRSA4Xkiqba1U+vcyNxArLyBl7DJFaw8gUWaYJs72CeBCELibvq/eq8QFP6vfgzDzxQz7Eb/8zm0pIjIjrbWWhv6Pj0bo1Fp7Yp1N0/P3m4XD8ogYBAwCBgEDAIGAYOAQcAgEH/7bfrqftpsS4vP34+FnRSeBdff0j5i/JSe9YSAQcAgYBAwCBgEDAIGAYOAQcAgEMP5K/2WGfprafHd9Dk9u/g4pGdjkv+sUOUJAYOAQcAgYBAwCBgEDAIGAYPAuDQdtX5v35f07MsNr+MVnhAwCBgEDAIGAYOAQcAgYBAwCJSu7qtuVlr89Xwqzd8DTwgYBAwCBgGDgEHAIGAQMAgYBAwCsWxd+g+iR3ybVHlCwCBgEDAIGAQMAgYBg4BBwCDwD47LJOkN00QZAAAAAElFTkSuQmCC\" id=\"image69ff97cdd8\" transform=\"scale(1 -1)translate(0 -68)\" x=\"115.757147\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_11\">\n","    <g id=\"xtick_11\">\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"121.418016\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_17\">\n","      <!-- 0 -->\n","      <g transform=\"translate(118.236766 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_12\">\n","     <g id=\"line2d_27\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"178.026712\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_18\">\n","      <!-- 5 -->\n","      <g transform=\"translate(174.845462 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_19\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(116.659083 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_12\">\n","    <g id=\"ytick_16\">\n","     <g id=\"line2d_28\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"131.757176\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_17\">\n","     <g id=\"line2d_29\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"154.400655\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_18\">\n","     <g id=\"line2d_30\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"115.757147\" y=\"177.044133\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_28\">\n","    <path d=\"M 115.757147 194.026742 \n","L 115.757147 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_29\">\n","    <path d=\"M 183.687582 194.026742 \n","L 183.687582 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_30\">\n","    <path d=\"M 115.757147 194.026742 \n","L 183.687582 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_31\">\n","    <path d=\"M 115.757147 126.096307 \n","L 183.687582 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_20\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_7\">\n","   <g id=\"patch_32\">\n","    <path d=\"M 197.273668 194.026742 \n","L 265.204103 194.026742 \n","L 265.204103 126.096307 \n","L 197.273668 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pce4f6eb9f9)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAAA7UlEQVR4nO3aO04DMRRA0XHawA5gfXz2g2B/YQE002Yo6G5lFxGKdE79ZFlXLmzJ4317PLZJH/tldnTZcb1Oz47T6Wb7uN3Kd0qQECQECUFCkBAkBAlBQpAYx/4zfXU/junRv8XHWN7QjLfz89L858KTwwkJQUKQECQECUFCkBAkBAlBQpBYesu8np+WFv/av5c39N+ckBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQECQECUFCkBAkBAlBQpAQJAQJQUKQGC/bw/QPonv8EbTKCQlBQpAQJAQJQUKQECQECUHiFx1ZHBEFcxAmAAAAAElFTkSuQmCC\" id=\"imagef54cf5bdcf\" transform=\"scale(1 -1)translate(0 -68)\" x=\"197.273668\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_13\">\n","    <g id=\"xtick_13\">\n","     <g id=\"line2d_31\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"202.934538\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_21\">\n","      <!-- 0 -->\n","      <g transform=\"translate(199.753288 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_14\">\n","     <g id=\"line2d_32\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"259.543234\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_22\">\n","      <!-- 5 -->\n","      <g transform=\"translate(256.361984 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_23\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(198.175605 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_14\">\n","    <g id=\"ytick_19\">\n","     <g id=\"line2d_33\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"131.757176\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_20\">\n","     <g id=\"line2d_34\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"154.400655\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_21\">\n","     <g id=\"line2d_35\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"197.273668\" y=\"177.044133\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_33\">\n","    <path d=\"M 197.273668 194.026742 \n","L 197.273668 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_34\">\n","    <path d=\"M 265.204103 194.026742 \n","L 265.204103 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_35\">\n","    <path d=\"M 197.273668 194.026742 \n","L 265.204103 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_36\">\n","    <path d=\"M 197.273668 126.096307 \n","L 265.204103 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_24\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_8\">\n","   <g id=\"patch_37\">\n","    <path d=\"M 278.79019 194.026742 \n","L 346.720625 194.026742 \n","L 346.720625 126.096307 \n","L 278.79019 126.096307 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pc36e9d3b6a)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAABECAYAAAA4E5OyAAABCklEQVR4nO3bMQ4BURRA0f9lojEVrS1Zg0pYg2WoWIO1WAGlQlQkqGRGobvV+xLJkHvql8nLzSummMmbetSmoNnpEB1NKaWUcy6aj2rb8Mpv13N4tFe4y98zCBgEDAIGAYOAQcAgYBAwCOT2fil8D457Lqfh2eb2CM/2V9tP1gnxQsAgYBAwCBgEDAIGAYOAQcAgYBCoSoYXg3HRw9f3Y9F8F3ghYBAwCBgEDAIGAYOAQcAgYBAwCBgEDAIGAYOAQcAgYBAwCBgEDAJVs9+FhyfD+ourdIMXAgYBg4BBwCBgEDAIGAQMAgYBg0Cepzr8N8QvfhFUygsBg4BBwCBgEDAIGAQMAgYBg8ALEqAdHIbZhGYAAAAASUVORK5CYII=\" id=\"image90ef3dbded\" transform=\"scale(1 -1)translate(0 -68)\" x=\"278.79019\" y=\"-126.026742\" width=\"68\" height=\"68\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_15\">\n","    <g id=\"xtick_15\">\n","     <g id=\"line2d_36\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"284.45106\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_25\">\n","      <!-- 0 -->\n","      <g transform=\"translate(281.26981 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_16\">\n","     <g id=\"line2d_37\">\n","      <g>\n","       <use xlink:href=\"#mc639b42e72\" x=\"341.059755\" y=\"194.026742\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_26\">\n","      <!-- 5 -->\n","      <g transform=\"translate(337.878505 208.625179)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_27\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(279.692126 222.303304)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_16\">\n","    <g id=\"ytick_22\">\n","     <g id=\"line2d_38\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"131.757176\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_23\">\n","     <g id=\"line2d_39\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"154.400655\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_24\">\n","     <g id=\"line2d_40\">\n","      <g>\n","       <use xlink:href=\"#mdd65203fa5\" x=\"278.79019\" y=\"177.044133\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_38\">\n","    <path d=\"M 278.79019 194.026742 \n","L 278.79019 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_39\">\n","    <path d=\"M 346.720625 194.026742 \n","L 346.720625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_40\">\n","    <path d=\"M 278.79019 194.026742 \n","L 346.720625 194.026742 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_41\">\n","    <path d=\"M 278.79019 126.096307 \n","L 346.720625 126.096307 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_28\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 120.096307)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_9\">\n","   <g id=\"patch_42\">\n","    <path d=\"M 366.250625 165.250433 \n","L 371.958425 165.250433 \n","L 371.958425 51.094433 \n","L 366.250625 51.094433 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_43\">\n","    <path clip-path=\"url(#pd864cf75a2)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAYAAAByCAYAAABwf6CfAAAAzElEQVR4nLXWQQ7DIBBDUSpx/7N2001hhl6AF2kQzTKW/fGQkLzW573a5upt5e5+6y0pBIS1RZwwlhmKqgtkZLkHhZgSCIfgkZhxDW5hjr3g5boHBTAOetAxNat6lGd1bz/cQ7M66KGH+qAH34/6fujIuAivCwcF9Z4HC5IBIcWgow5f89pyzRg8E6tRGTjbQ0LqaxAS6gxHlRmTzeuMfdJTD/0BpAQktZ5NBc1AVCiKDjP2hqeCcnBWFhTF5Q7tIB2zPJLvvSg6xv8ZP9W5DE4Qbu8+AAAAAElFTkSuQmCC\" id=\"image7a376798e3\" transform=\"scale(1 -1)translate(0 -114)\" x=\"366\" y=\"-51\" width=\"6\" height=\"114\"/>\n","   <g id=\"matplotlib.axis_17\">\n","    <g id=\"ytick_25\">\n","     <g id=\"line2d_41\">\n","      <defs>\n","       <path id=\"ma783607016\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"165.250433\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_29\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(378.958425 169.049652)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_26\">\n","     <g id=\"line2d_42\">\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"142.419233\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_30\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(378.958425 146.218452)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_27\">\n","     <g id=\"line2d_43\">\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"119.588033\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_31\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(378.958425 123.387252)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_28\">\n","     <g id=\"line2d_44\">\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"96.756833\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_32\">\n","      <!-- 0.6 -->\n","      <g transform=\"translate(378.958425 100.556052)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-36\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_29\">\n","     <g id=\"line2d_45\">\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"73.925633\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_33\">\n","      <!-- 0.8 -->\n","      <g transform=\"translate(378.958425 77.724852)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n","Q 1584 2216 1326 1975 \n","Q 1069 1734 1069 1313 \n","Q 1069 891 1326 650 \n","Q 1584 409 2034 409 \n","Q 2484 409 2743 651 \n","Q 3003 894 3003 1313 \n","Q 3003 1734 2745 1975 \n","Q 2488 2216 2034 2216 \n","z\n","M 1403 2484 \n","Q 997 2584 770 2862 \n","Q 544 3141 544 3541 \n","Q 544 4100 942 4425 \n","Q 1341 4750 2034 4750 \n","Q 2731 4750 3128 4425 \n","Q 3525 4100 3525 3541 \n","Q 3525 3141 3298 2862 \n","Q 3072 2584 2669 2484 \n","Q 3125 2378 3379 2068 \n","Q 3634 1759 3634 1313 \n","Q 3634 634 3220 271 \n","Q 2806 -91 2034 -91 \n","Q 1263 -91 848 271 \n","Q 434 634 434 1313 \n","Q 434 1759 690 2068 \n","Q 947 2378 1403 2484 \n","z\n","M 1172 3481 \n","Q 1172 3119 1398 2916 \n","Q 1625 2713 2034 2713 \n","Q 2441 2713 2670 2916 \n","Q 2900 3119 2900 3481 \n","Q 2900 3844 2670 4047 \n","Q 2441 4250 2034 4250 \n","Q 1625 4250 1398 4047 \n","Q 1172 3844 1172 3481 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-38\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_30\">\n","     <g id=\"line2d_46\">\n","      <g>\n","       <use xlink:href=\"#ma783607016\" x=\"371.958425\" y=\"51.094433\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_34\">\n","      <!-- 1.0 -->\n","      <g transform=\"translate(378.958425 54.893652)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-31\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_44\">\n","    <path d=\"M 366.250625 165.250433 \n","L 369.104525 165.250433 \n","L 371.958425 165.250433 \n","L 371.958425 51.094433 \n","L 369.104525 51.094433 \n","L 366.250625 51.094433 \n","L 366.250625 165.250433 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p589e8b64e0\">\n","   <rect x=\"34.240625\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p43a16bca14\">\n","   <rect x=\"115.757147\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p96774354a8\">\n","   <rect x=\"197.273668\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pac315db926\">\n","   <rect x=\"278.79019\" y=\"22.318125\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pe2f387b989\">\n","   <rect x=\"34.240625\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"p97e481024a\">\n","   <rect x=\"115.757147\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pce4f6eb9f9\">\n","   <rect x=\"197.273668\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pc36e9d3b6a\">\n","   <rect x=\"278.79019\" y=\"126.096307\" width=\"67.930435\" height=\"67.930435\"/>\n","  </clipPath>\n","  <clipPath id=\"pd864cf75a2\">\n","   <rect x=\"366.250625\" y=\"51.094433\" width=\"5.7078\" height=\"114.156\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 504x252 with 9 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["# Plusonetoincludethebeginning-of-sequencetoken\n","d2l.show_heatmaps(\n","    dec_self_attention_weights[:, :, :, :len(translation.split()) + 1],\n","    xlabel='Key positions', ylabel='Query positions',\n","    titles=['Head %d' % i for i in range(1, 5)], figsize=(7, 3.5))"],"id":"065c21cf"},{"cell_type":"markdown","metadata":{"origin_pos":70,"id":"bf1c85ff"},"source":["与编码器的自注意力的情况类似，通过指定输入序列的有效长度，[**输出序列的查询不会与输入序列中填充位置的词元进行注意力计算**]。\n"],"id":"bf1c85ff"},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2022-07-31T03:03:13.236550Z","iopub.status.busy":"2022-07-31T03:03:13.236271Z","iopub.status.idle":"2022-07-31T03:03:13.917649Z","shell.execute_reply":"2022-07-31T03:03:13.916772Z"},"origin_pos":71,"tab":["pytorch"],"id":"c4229176","outputId":"5af189fa-7f36-4145-af74-4fa987c9a6c3"},"outputs":[{"data":{"image/svg+xml":["<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n","<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n","  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n","<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"402.06155pt\" height=\"208.108094pt\" viewBox=\"0 0 402.06155 208.108094\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n"," <metadata>\n","  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n","   <cc:Work>\n","    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n","    <dc:date>2022-07-31T03:03:13.771566</dc:date>\n","    <dc:format>image/svg+xml</dc:format>\n","    <dc:creator>\n","     <cc:Agent>\n","      <dc:title>Matplotlib v3.5.1, https://matplotlib.org/</dc:title>\n","     </cc:Agent>\n","    </dc:creator>\n","   </cc:Work>\n","  </rdf:RDF>\n"," </metadata>\n"," <defs>\n","  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n"," </defs>\n"," <g id=\"figure_1\">\n","  <g id=\"patch_1\">\n","   <path d=\"M 0 208.108094 \n","L 402.06155 208.108094 \n","L 402.06155 0 \n","L 0 0 \n","L 0 208.108094 \n","z\n","\" style=\"fill: none\"/>\n","  </g>\n","  <g id=\"axes_1\">\n","   <g id=\"patch_2\">\n","    <path d=\"M 34.240625 66.773662 \n","L 102.17106 66.773662 \n","L 102.17106 26.015401 \n","L 34.240625 26.015401 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p018777eeb2)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABBUlEQVR4nO3YMWoCURRA0fk6mQmOKa0SsoBAkgVkFdlEcDU2Fm7Bzj1kA1YpLCRNGgshpWB00l/mCSIyCveU//Hhc3kwaPqbjessUC++olGWnl4bzzsvb/GdwWM4uxSdth9waQwCBgGDgEHAIJD265/ws5tu++HFzcd743m3X4Z3bkbTI57WDjcEDAIGAYOAQcAgkGdlFQ6H1UM4m/wumwfbzalvapUbAgYBg4BBwCBgEMgPDe+6B3rtts3n+/DH81VwQ8AgYBAwCBgE8nr1HQ6fqyK+mYKWRfyf6jVwQ8AgYBAwCBgEDAJ5Pf8Mh/dF/NlNZe8c72mdGwIGAYOAQcAgYBD4B0YbHPyVH8W/AAAAAElFTkSuQmCC\" id=\"image1f531dad2c\" transform=\"scale(1 -1)translate(0 -41)\" x=\"34.240625\" y=\"-25.773662\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_1\">\n","    <g id=\"xtick_1\">\n","     <g id=\"line2d_1\">\n","      <defs>\n","       <path id=\"m3141869086\" d=\"M 0 0 \n","L 0 3.5 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"37.637147\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_2\">\n","     <g id=\"line2d_2\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"71.602364\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_2\">\n","    <g id=\"ytick_1\">\n","     <g id=\"line2d_3\">\n","      <defs>\n","       <path id=\"m55a80ebdb0\" d=\"M 0 0 \n","L -3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"34.240625\" y=\"29.411923\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_1\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 33.211141)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n","Q 1547 4250 1301 3770 \n","Q 1056 3291 1056 2328 \n","Q 1056 1369 1301 889 \n","Q 1547 409 2034 409 \n","Q 2525 409 2770 889 \n","Q 3016 1369 3016 2328 \n","Q 3016 3291 2770 3770 \n","Q 2525 4250 2034 4250 \n","z\n","M 2034 4750 \n","Q 2819 4750 3233 4129 \n","Q 3647 3509 3647 2328 \n","Q 3647 1150 3233 529 \n","Q 2819 -91 2034 -91 \n","Q 1250 -91 836 529 \n","Q 422 1150 422 2328 \n","Q 422 3509 836 4129 \n","Q 1250 4750 2034 4750 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_2\">\n","     <g id=\"line2d_4\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"34.240625\" y=\"63.37714\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_2\">\n","      <!-- 5 -->\n","      <g transform=\"translate(20.878125 67.176359)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n","L 3169 4666 \n","L 3169 4134 \n","L 1269 4134 \n","L 1269 2991 \n","Q 1406 3038 1543 3061 \n","Q 1681 3084 1819 3084 \n","Q 2600 3084 3056 2656 \n","Q 3513 2228 3513 1497 \n","Q 3513 744 3044 326 \n","Q 2575 -91 1722 -91 \n","Q 1428 -91 1123 -41 \n","Q 819 9 494 109 \n","L 494 744 \n","Q 775 591 1075 516 \n","Q 1375 441 1709 441 \n","Q 2250 441 2565 725 \n","Q 2881 1009 2881 1497 \n","Q 2881 1984 2565 2268 \n","Q 2250 2553 1709 2553 \n","Q 1456 2553 1204 2497 \n","Q 953 2441 691 2322 \n","L 691 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_3\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 85.589063)rotate(-90)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-51\" d=\"M 2522 4238 \n","Q 1834 4238 1429 3725 \n","Q 1025 3213 1025 2328 \n","Q 1025 1447 1429 934 \n","Q 1834 422 2522 422 \n","Q 3209 422 3611 934 \n","Q 4013 1447 4013 2328 \n","Q 4013 3213 3611 3725 \n","Q 3209 4238 2522 4238 \n","z\n","M 3406 84 \n","L 4238 -825 \n","L 3475 -825 \n","L 2784 -78 \n","Q 2681 -84 2626 -87 \n","Q 2572 -91 2522 -91 \n","Q 1538 -91 948 567 \n","Q 359 1225 359 2328 \n","Q 359 3434 948 4092 \n","Q 1538 4750 2522 4750 \n","Q 3503 4750 4090 4092 \n","Q 4678 3434 4678 2328 \n","Q 4678 1516 4351 937 \n","Q 4025 359 3406 84 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-75\" d=\"M 544 1381 \n","L 544 3500 \n","L 1119 3500 \n","L 1119 1403 \n","Q 1119 906 1312 657 \n","Q 1506 409 1894 409 \n","Q 2359 409 2629 706 \n","Q 2900 1003 2900 1516 \n","L 2900 3500 \n","L 3475 3500 \n","L 3475 0 \n","L 2900 0 \n","L 2900 538 \n","Q 2691 219 2414 64 \n","Q 2138 -91 1772 -91 \n","Q 1169 -91 856 284 \n","Q 544 659 544 1381 \n","z\n","M 1991 3584 \n","L 1991 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n","L 3597 1613 \n","L 953 1613 \n","Q 991 1019 1311 708 \n","Q 1631 397 2203 397 \n","Q 2534 397 2845 478 \n","Q 3156 559 3463 722 \n","L 3463 178 \n","Q 3153 47 2828 -22 \n","Q 2503 -91 2169 -91 \n","Q 1331 -91 842 396 \n","Q 353 884 353 1716 \n","Q 353 2575 817 3079 \n","Q 1281 3584 2069 3584 \n","Q 2775 3584 3186 3129 \n","Q 3597 2675 3597 1894 \n","z\n","M 3022 2063 \n","Q 3016 2534 2758 2815 \n","Q 2500 3097 2075 3097 \n","Q 1594 3097 1305 2825 \n","Q 1016 2553 972 2059 \n","L 3022 2063 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n","Q 2534 3019 2420 3045 \n","Q 2306 3072 2169 3072 \n","Q 1681 3072 1420 2755 \n","Q 1159 2438 1159 1844 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1341 3275 1631 3429 \n","Q 1922 3584 2338 3584 \n","Q 2397 3584 2469 3576 \n","Q 2541 3569 2628 3553 \n","L 2631 2963 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n","Q 1816 -950 1584 -1140 \n","Q 1353 -1331 966 -1331 \n","L 506 -1331 \n","L 506 -850 \n","L 844 -850 \n","Q 1081 -850 1212 -737 \n","Q 1344 -625 1503 -206 \n","L 1606 56 \n","L 191 3500 \n","L 800 3500 \n","L 1894 763 \n","L 2988 3500 \n","L 3597 3500 \n","L 2059 -325 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n","L 1159 -1331 \n","L 581 -1331 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2969 \n","Q 1341 3281 1617 3432 \n","Q 1894 3584 2278 3584 \n","Q 2916 3584 3314 3078 \n","Q 3713 2572 3713 1747 \n","Q 3713 922 3314 415 \n","Q 2916 -91 2278 -91 \n","Q 1894 -91 1617 61 \n","Q 1341 213 1159 525 \n","z\n","M 3116 1747 \n","Q 3116 2381 2855 2742 \n","Q 2594 3103 2138 3103 \n","Q 1681 3103 1420 2742 \n","Q 1159 2381 1159 1747 \n","Q 1159 1113 1420 752 \n","Q 1681 391 2138 391 \n","Q 2594 391 2855 752 \n","Q 3116 1113 3116 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n","Q 1497 3097 1228 2736 \n","Q 959 2375 959 1747 \n","Q 959 1119 1226 758 \n","Q 1494 397 1959 397 \n","Q 2419 397 2687 759 \n","Q 2956 1122 2956 1747 \n","Q 2956 2369 2687 2733 \n","Q 2419 3097 1959 3097 \n","z\n","M 1959 3584 \n","Q 2709 3584 3137 3096 \n","Q 3566 2609 3566 1747 \n","Q 3566 888 3137 398 \n","Q 2709 -91 1959 -91 \n","Q 1206 -91 779 398 \n","Q 353 888 353 1747 \n","Q 353 2609 779 3096 \n","Q 1206 3584 1959 3584 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \n","L 2834 2853 \n","Q 2591 2978 2328 3040 \n","Q 2066 3103 1784 3103 \n","Q 1356 3103 1142 2972 \n","Q 928 2841 928 2578 \n","Q 928 2378 1081 2264 \n","Q 1234 2150 1697 2047 \n","L 1894 2003 \n","Q 2506 1872 2764 1633 \n","Q 3022 1394 3022 966 \n","Q 3022 478 2636 193 \n","Q 2250 -91 1575 -91 \n","Q 1294 -91 989 -36 \n","Q 684 19 347 128 \n","L 347 722 \n","Q 666 556 975 473 \n","Q 1284 391 1588 391 \n","Q 1994 391 2212 530 \n","Q 2431 669 2431 922 \n","Q 2431 1156 2273 1281 \n","Q 2116 1406 1581 1522 \n","L 1381 1569 \n","Q 847 1681 609 1914 \n","Q 372 2147 372 2553 \n","Q 372 3047 722 3315 \n","Q 1072 3584 1716 3584 \n","Q 2034 3584 2315 3537 \n","Q 2597 3491 2834 3397 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n","L 1178 3500 \n","L 1178 0 \n","L 603 0 \n","L 603 3500 \n","z\n","M 603 4863 \n","L 1178 4863 \n","L 1178 4134 \n","L 603 4134 \n","L 603 4863 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n","L 1172 3500 \n","L 2356 3500 \n","L 2356 3053 \n","L 1172 3053 \n","L 1172 1153 \n","Q 1172 725 1289 603 \n","Q 1406 481 1766 481 \n","L 2356 481 \n","L 2356 0 \n","L 1766 0 \n","Q 1100 0 847 248 \n","Q 594 497 594 1153 \n","L 594 3053 \n","L 172 3053 \n","L 172 3500 \n","L 594 3500 \n","L 594 4494 \n","L 1172 4494 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \n","L 3513 0 \n","L 2938 0 \n","L 2938 2094 \n","Q 2938 2591 2744 2837 \n","Q 2550 3084 2163 3084 \n","Q 1697 3084 1428 2787 \n","Q 1159 2491 1159 1978 \n","L 1159 0 \n","L 581 0 \n","L 581 3500 \n","L 1159 3500 \n","L 1159 2956 \n","Q 1366 3272 1645 3428 \n","Q 1925 3584 2291 3584 \n","Q 2894 3584 3203 3211 \n","Q 3513 2838 3513 2113 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_3\">\n","    <path d=\"M 34.240625 66.773662 \n","L 34.240625 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_4\">\n","    <path d=\"M 102.17106 66.773662 \n","L 102.17106 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_5\">\n","    <path d=\"M 34.240625 66.773662 \n","L 102.17106 66.773662 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_6\">\n","    <path d=\"M 34.240625 26.015401 \n","L 102.17106 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_4\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 20.015401)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-48\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2753 \n","L 3553 2753 \n","L 3553 4666 \n","L 4184 4666 \n","L 4184 0 \n","L 3553 0 \n","L 3553 2222 \n","L 1259 2222 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n","Q 1497 1759 1228 1600 \n","Q 959 1441 959 1056 \n","Q 959 750 1161 570 \n","Q 1363 391 1709 391 \n","Q 2188 391 2477 730 \n","Q 2766 1069 2766 1631 \n","L 2766 1759 \n","L 2194 1759 \n","z\n","M 3341 1997 \n","L 3341 0 \n","L 2766 0 \n","L 2766 531 \n","Q 2569 213 2275 61 \n","Q 1981 -91 1556 -91 \n","Q 1019 -91 701 211 \n","Q 384 513 384 1019 \n","Q 384 1609 779 1909 \n","Q 1175 2209 1959 2209 \n","L 2766 2209 \n","L 2766 2266 \n","Q 2766 2663 2505 2880 \n","Q 2244 3097 1772 3097 \n","Q 1472 3097 1187 3025 \n","Q 903 2953 641 2809 \n","L 641 3341 \n","Q 956 3463 1253 3523 \n","Q 1550 3584 1831 3584 \n","Q 2591 3584 2966 3190 \n","Q 3341 2797 3341 1997 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \n","L 2906 4863 \n","L 3481 4863 \n","L 3481 0 \n","L 2906 0 \n","L 2906 525 \n","Q 2725 213 2448 61 \n","Q 2172 -91 1784 -91 \n","Q 1150 -91 751 415 \n","Q 353 922 353 1747 \n","Q 353 2572 751 3078 \n","Q 1150 3584 1784 3584 \n","Q 2172 3584 2448 3432 \n","Q 2725 3281 2906 2969 \n","z\n","M 947 1747 \n","Q 947 1113 1208 752 \n","Q 1469 391 1925 391 \n","Q 2381 391 2643 752 \n","Q 2906 1113 2906 1747 \n","Q 2906 2381 2643 2742 \n","Q 2381 3103 1925 3103 \n","Q 1469 3103 1208 2742 \n","Q 947 2381 947 1747 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      <path id=\"DejaVuSans-31\" d=\"M 794 531 \n","L 1825 531 \n","L 1825 4091 \n","L 703 3866 \n","L 703 4441 \n","L 1819 4666 \n","L 2450 4666 \n","L 2450 531 \n","L 3481 531 \n","L 3481 0 \n","L 794 0 \n","L 794 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_2\">\n","   <g id=\"patch_7\">\n","    <path d=\"M 115.757147 66.773662 \n","L 183.687582 66.773662 \n","L 183.687582 26.015401 \n","L 115.757147 26.015401 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p587607e1a4)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABGklEQVR4nO3ZP0oDQRhA8Z0kGvyDEnIJwdbaW0jOYGetJ/AEYmNrTqBFmqQQbQXBTptUwjZGxMIk9o/5ZMFiIrxfuR/DDo+BZXfT93i4rCLbu+FoObnJXk+9frimPTgJZ6uiVXoDq8YgYBAwCBgEDAKdavoaDp/PLsPZ/v0oP9jc+eueivKEgEHAIGAQMAgYBNKinoZvu8f9vXDhxdtTfrDWjW+2vtF8Z4V4QsAgYBAwCBgEDAJpMavjj8zvdTiaX51nr89uH8I1vdFd850V4gkBg4BBwCBgEEifg8PwKTP/+AoXbl3nf2VWrXZ8s5Sa76wQTwgYBAwCBgGDgEGg8zh+CYcHp0fxyl8er/+ZJwQMAgYBg4BBwCDwA1BbKcnC5HrfAAAAAElFTkSuQmCC\" id=\"image5c31a8a474\" transform=\"scale(1 -1)translate(0 -41)\" x=\"115.757147\" y=\"-25.773662\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_3\">\n","    <g id=\"xtick_3\">\n","     <g id=\"line2d_5\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"119.153668\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_4\">\n","     <g id=\"line2d_6\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"153.118886\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_4\">\n","    <g id=\"ytick_3\">\n","     <g id=\"line2d_7\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"115.757147\" y=\"29.411923\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_4\">\n","     <g id=\"line2d_8\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"115.757147\" y=\"63.37714\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_8\">\n","    <path d=\"M 115.757147 66.773662 \n","L 115.757147 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_9\">\n","    <path d=\"M 183.687582 66.773662 \n","L 183.687582 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_10\">\n","    <path d=\"M 115.757147 66.773662 \n","L 183.687582 66.773662 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_11\">\n","    <path d=\"M 115.757147 26.015401 \n","L 183.687582 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_5\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 20.015401)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n","L 3431 531 \n","L 3431 0 \n","L 469 0 \n","L 469 531 \n","Q 828 903 1448 1529 \n","Q 2069 2156 2228 2338 \n","Q 2531 2678 2651 2914 \n","Q 2772 3150 2772 3378 \n","Q 2772 3750 2511 3984 \n","Q 2250 4219 1831 4219 \n","Q 1534 4219 1204 4116 \n","Q 875 4013 500 3803 \n","L 500 4441 \n","Q 881 4594 1212 4672 \n","Q 1544 4750 1819 4750 \n","Q 2544 4750 2975 4387 \n","Q 3406 4025 3406 3419 \n","Q 3406 3131 3298 2873 \n","Q 3191 2616 2906 2266 \n","Q 2828 2175 2409 1742 \n","Q 1991 1309 1228 531 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_3\">\n","   <g id=\"patch_12\">\n","    <path d=\"M 197.273668 66.773662 \n","L 265.204103 66.773662 \n","L 265.204103 26.015401 \n","L 197.273668 26.015401 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p444ff43be0)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABJElEQVR4nO3YP0oDQRiG8f02pjD+IVhoQI9gbaEW2irYWniBFHoX0cITeAPBq6SyiY2FsKIShLBj/zKvbOVO8fzKXb7Z4WFgYKN9naXKaJ8f3auqWh3ln+/s2pHB4YVfrxB13xsoDUEEQQRBBEEEQUQ8bU3stXs+n9nB1Ly5Jf3HxtudN9YXToggiCCIIIggiCCIiMXVqb12h0cHdrC+vMm/WC79x9bHnTfWF06IIIggiCCIIIggiIj2891eux9nJ3Zw8/42+zz9LOzMYP+488b6wgkRBBEEEQQRBBFxHRv2lrlrXvzgyjD7PCW7XBXh/7eWghMiCCIIIggiCCIIIiJ9N/aenK7t2cGHr3n+xV/Xbl1+//J3+M8IIggiCCIIIggifgGcTy2fzfCp2gAAAABJRU5ErkJggg==\" id=\"image52e51c1fe1\" transform=\"scale(1 -1)translate(0 -41)\" x=\"197.273668\" y=\"-25.773662\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_5\">\n","    <g id=\"xtick_5\">\n","     <g id=\"line2d_9\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"200.67019\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_6\">\n","     <g id=\"line2d_10\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"234.635408\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_6\">\n","    <g id=\"ytick_5\">\n","     <g id=\"line2d_11\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"197.273668\" y=\"29.411923\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_6\">\n","     <g id=\"line2d_12\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"197.273668\" y=\"63.37714\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_13\">\n","    <path d=\"M 197.273668 66.773662 \n","L 197.273668 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_14\">\n","    <path d=\"M 265.204103 66.773662 \n","L 265.204103 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_15\">\n","    <path d=\"M 197.273668 66.773662 \n","L 265.204103 66.773662 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_16\">\n","    <path d=\"M 197.273668 26.015401 \n","L 265.204103 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_6\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 20.015401)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n","Q 3050 2419 3304 2112 \n","Q 3559 1806 3559 1356 \n","Q 3559 666 3084 287 \n","Q 2609 -91 1734 -91 \n","Q 1441 -91 1130 -33 \n","Q 819 25 488 141 \n","L 488 750 \n","Q 750 597 1062 519 \n","Q 1375 441 1716 441 \n","Q 2309 441 2620 675 \n","Q 2931 909 2931 1356 \n","Q 2931 1769 2642 2001 \n","Q 2353 2234 1838 2234 \n","L 1294 2234 \n","L 1294 2753 \n","L 1863 2753 \n","Q 2328 2753 2575 2939 \n","Q 2822 3125 2822 3475 \n","Q 2822 3834 2567 4026 \n","Q 2313 4219 1838 4219 \n","Q 1578 4219 1281 4162 \n","Q 984 4106 628 3988 \n","L 628 4550 \n","Q 988 4650 1302 4700 \n","Q 1616 4750 1894 4750 \n","Q 2613 4750 3031 4423 \n","Q 3450 4097 3450 3541 \n","Q 3450 3153 3228 2886 \n","Q 3006 2619 2597 2516 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_4\">\n","   <g id=\"patch_17\">\n","    <path d=\"M 278.79019 66.773662 \n","L 346.720625 66.773662 \n","L 346.720625 26.015401 \n","L 278.79019 26.015401 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p7632c1e4c6)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABJUlEQVR4nO3YMUoDQRiG4Z1ljUFBm1haCd4gjSA5QCorEUFPIKQQS69gJdbBI2gjSG5gkyLY2Gklgk0Cq8ZJ/zGfRCwmwvuU8zPZ4WVgICGO32NhxHriRsX4eC+5Xi4v2T0r/Vs7WxRl7gMsGoIIggiCCIIIgohwvdayz+7hcGA3xs86/YOtTf+xRvMXR8uDGyIIIggiCCIIIggiwtfDnX12L3cP7MaTl1F68D31H2uuzn+yTLghgiCCIIIggiCCIKIqt9t2OJp8+J3uD+gfnt2CZ/f/IYggiCCIIIiophendnj19mhnde8oud44O7d7wvrG/CfLhBsiCCIIIggiCCIIIqrQ3bfDp52OnW3d3yTX4+vznw+VEzdEEEQQRBBEEEQQRMwAeZcuujprZVsAAAAASUVORK5CYII=\" id=\"imagec6eabe7b7c\" transform=\"scale(1 -1)translate(0 -41)\" x=\"278.79019\" y=\"-25.773662\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_7\">\n","    <g id=\"xtick_7\">\n","     <g id=\"line2d_13\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"282.186712\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_8\">\n","     <g id=\"line2d_14\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"316.151929\" y=\"66.773662\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_8\">\n","    <g id=\"ytick_7\">\n","     <g id=\"line2d_15\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"278.79019\" y=\"29.411923\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_8\">\n","     <g id=\"line2d_16\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"278.79019\" y=\"63.37714\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_18\">\n","    <path d=\"M 278.79019 66.773662 \n","L 278.79019 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_19\">\n","    <path d=\"M 346.720625 66.773662 \n","L 346.720625 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_20\">\n","    <path d=\"M 278.79019 66.773662 \n","L 346.720625 66.773662 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_21\">\n","    <path d=\"M 278.79019 26.015401 \n","L 346.720625 26.015401 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_7\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 20.015401)scale(0.12 -0.12)\">\n","     <defs>\n","      <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n","L 825 1625 \n","L 2419 1625 \n","L 2419 4116 \n","z\n","M 2253 4666 \n","L 3047 4666 \n","L 3047 1625 \n","L 3713 1625 \n","L 3713 1100 \n","L 3047 1100 \n","L 3047 0 \n","L 2419 0 \n","L 2419 1100 \n","L 313 1100 \n","L 313 1709 \n","L 2253 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","     </defs>\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_5\">\n","   <g id=\"patch_22\">\n","    <path d=\"M 34.240625 170.551844 \n","L 102.17106 170.551844 \n","L 102.17106 129.793583 \n","L 34.240625 129.793583 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p0fb1186da0)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABIUlEQVR4nO3ZsUpCURzH8XvsEl5BxTIIosEhcApaxVdouEQP0XM0ODU72Vpv0NoD1NjSC4gkSOKmWfuX84PbdO7w+4z++evhywG53LB7e/nNhMb5UI2yn9kkPlgu5U5+/yhnddFIfYC6cRBwEHAQcBBwEMhDt6+nu62eFUV8ZbHSP1b1VAn5hoCDgIOAg4CDgINA2JQj+bTbvLnWi1fj+OftI71zfPaPo6XhGwIOAg4CDgIOAg4CYb+ay7/du96FXJx+faiv1D/W6lQ+WCq+IeAg4CDgIOAgkGdr/erxobyUs/3ne3yw+ZY7B+Oy8sFS8Q0BBwEHAQcBBwEHgfDcPZEPd7evT3rxdBAfNFt65zD++rNOfEPAQcBBwEHAQcBB4A/gKSTo4KkY7QAAAABJRU5ErkJggg==\" id=\"image0b0ee645e3\" transform=\"scale(1 -1)translate(0 -41)\" x=\"34.240625\" y=\"-129.551844\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_9\">\n","    <g id=\"xtick_9\">\n","     <g id=\"line2d_17\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"37.637147\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_8\">\n","      <!-- 0 -->\n","      <g transform=\"translate(34.455897 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_10\">\n","     <g id=\"line2d_18\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"71.602364\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_9\">\n","      <!-- 5 -->\n","      <g transform=\"translate(68.421114 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_10\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(35.142561 198.828406)scale(0.1 -0.1)\">\n","      <defs>\n","       <path id=\"DejaVuSans-4b\" d=\"M 628 4666 \n","L 1259 4666 \n","L 1259 2694 \n","L 3353 4666 \n","L 4166 4666 \n","L 1850 2491 \n","L 4331 0 \n","L 3500 0 \n","L 1259 2247 \n","L 1259 0 \n","L 628 0 \n","L 628 4666 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","      </defs>\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_10\">\n","    <g id=\"ytick_9\">\n","     <g id=\"line2d_19\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"34.240625\" y=\"133.190104\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_11\">\n","      <!-- 0 -->\n","      <g transform=\"translate(20.878125 136.989323)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_10\">\n","     <g id=\"line2d_20\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"34.240625\" y=\"167.155322\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_12\">\n","      <!-- 5 -->\n","      <g transform=\"translate(20.878125 170.954541)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_13\">\n","     <!-- Query positions -->\n","     <g transform=\"translate(14.798437 189.367244)rotate(-90)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-51\"/>\n","      <use xlink:href=\"#DejaVuSans-75\" x=\"78.710938\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"142.089844\"/>\n","      <use xlink:href=\"#DejaVuSans-72\" x=\"203.613281\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"244.726562\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"303.90625\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"335.693359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"399.169922\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"460.351562\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"512.451172\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"540.234375\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"579.443359\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"607.226562\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"668.408203\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"731.787109\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_23\">\n","    <path d=\"M 34.240625 170.551844 \n","L 34.240625 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_24\">\n","    <path d=\"M 102.17106 170.551844 \n","L 102.17106 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_25\">\n","    <path d=\"M 34.240625 170.551844 \n","L 102.17106 170.551844 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_26\">\n","    <path d=\"M 34.240625 129.793583 \n","L 102.17106 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_14\">\n","    <!-- Head 1 -->\n","    <g transform=\"translate(46.791467 123.793583)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-31\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_6\">\n","   <g id=\"patch_27\">\n","    <path d=\"M 115.757147 170.551844 \n","L 183.687582 170.551844 \n","L 183.687582 129.793583 \n","L 115.757147 129.793583 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pf65d476a50)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABHklEQVR4nO3XPUoDQRyG8ZlsigRTBAsFiXoNS49g5R2sYq21tUiKXMAzWFnY2IhpLBSs7EXyZYoQnNi/7BsWUswWz6/cP7M7PAwsE1eXZ+tgFNd3bhTSx0v5YD62a4rTczuri0buDdQNQQRBBEEEQQRBREzTb/vbDcGP/gZXpc+Xo3e7Zuf+ofLGcuGECIIIggiCCIIIgohmWEzsML0+2lk86JU+b/WOt91TVpwQQRBBEEEQQRBBEBHT79heaS86h3bhcPZl3hj9xxpF5Y3lwgkRBBEEEQQRBBHN9PZkhzcnR37l/McM/F8mdPcqbSonToggiCCIIIggiCCIiLftXXu5638++5XdffPGDZe7DbO64IQIggiCCIIIggiCiH89dCk2u1vSaAAAAABJRU5ErkJggg==\" id=\"image7389779c7c\" transform=\"scale(1 -1)translate(0 -41)\" x=\"115.757147\" y=\"-129.551844\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_11\">\n","    <g id=\"xtick_11\">\n","     <g id=\"line2d_21\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"119.153668\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_15\">\n","      <!-- 0 -->\n","      <g transform=\"translate(115.972418 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_12\">\n","     <g id=\"line2d_22\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"153.118886\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_16\">\n","      <!-- 5 -->\n","      <g transform=\"translate(149.937636 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_17\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(116.659083 198.828406)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_12\">\n","    <g id=\"ytick_11\">\n","     <g id=\"line2d_23\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"115.757147\" y=\"133.190104\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_12\">\n","     <g id=\"line2d_24\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"115.757147\" y=\"167.155322\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_28\">\n","    <path d=\"M 115.757147 170.551844 \n","L 115.757147 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_29\">\n","    <path d=\"M 183.687582 170.551844 \n","L 183.687582 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_30\">\n","    <path d=\"M 115.757147 170.551844 \n","L 183.687582 170.551844 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_31\">\n","    <path d=\"M 115.757147 129.793583 \n","L 183.687582 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_18\">\n","    <!-- Head 2 -->\n","    <g transform=\"translate(128.307989 123.793583)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-32\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_7\">\n","   <g id=\"patch_32\">\n","    <path d=\"M 197.273668 170.551844 \n","L 265.204103 170.551844 \n","L 265.204103 129.793583 \n","L 197.273668 129.793583 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#p586cf36bc6)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABIklEQVR4nO3YMUoDQRiG4Z1M1krB2NhrCrGTWKaIB7A0V7AS72BhaRXwAHqDFIGQKp2WwVoCgWAhXkDdtX+ZDxYsZovvKffnX4aXgSUJP0/3dSGE8ws1KuqXhRhUcieOb+WsLTq5D9A2DgIOAg4CDgIOAt3v2VwOy9OB3jw6ST4Oe73/nikr3xBwEHAQcBBwEHAQCNV6JX/t/k7u9OJwlB6UO3InjsaND5aLbwg4CDgIOAg4CDgIhOprKz+70+MzuXj5tkw+rz+3cqfT1+9rC98QcBBwEHAQcBAI18Wu/Mo8bl715v5h+nktX1eE2G18sFx8Q8BBwEHAQcBBwEEgVB/v+j/V5we92DtID2Ipd+LVTfOTZeIbAg4CDgIOAg4CDgJ/PlQp9kO4BN4AAAAASUVORK5CYII=\" id=\"image2b1948fb71\" transform=\"scale(1 -1)translate(0 -41)\" x=\"197.273668\" y=\"-129.551844\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_13\">\n","    <g id=\"xtick_13\">\n","     <g id=\"line2d_25\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"200.67019\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_19\">\n","      <!-- 0 -->\n","      <g transform=\"translate(197.48894 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_14\">\n","     <g id=\"line2d_26\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"234.635408\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_20\">\n","      <!-- 5 -->\n","      <g transform=\"translate(231.454158 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_21\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(198.175605 198.828406)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_14\">\n","    <g id=\"ytick_13\">\n","     <g id=\"line2d_27\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"197.273668\" y=\"133.190104\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_14\">\n","     <g id=\"line2d_28\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"197.273668\" y=\"167.155322\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_33\">\n","    <path d=\"M 197.273668 170.551844 \n","L 197.273668 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_34\">\n","    <path d=\"M 265.204103 170.551844 \n","L 265.204103 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_35\">\n","    <path d=\"M 197.273668 170.551844 \n","L 265.204103 170.551844 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_36\">\n","    <path d=\"M 197.273668 129.793583 \n","L 265.204103 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_22\">\n","    <!-- Head 3 -->\n","    <g transform=\"translate(209.824511 123.793583)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-33\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_8\">\n","   <g id=\"patch_37\">\n","    <path d=\"M 278.79019 170.551844 \n","L 346.720625 170.551844 \n","L 346.720625 129.793583 \n","L 278.79019 129.793583 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g clip-path=\"url(#pc03a8a644f)\">\n","    <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAEQAAAApCAYAAACMeY82AAABCUlEQVR4nO3YMUpDQRRA0ZlkTASVNELAJkUQVyaW2oiNhaWV2GUrLkBwCXaKhbWggqB+v/1lnghBJsI95X9MGC4PBpK725s+BfLOPBql7vywPphOwzNl/yycrYpB6wusGoOAQcAgYBAwCJQ82Y6n3Wc4+rh7rH4f7e4te6em3BAwCBgEDAIGAYNASRuTcNhdHIez8clp9Xt/fbX0pVpyQ8AgYBAwCBgEDAL56/Up/JP5aGsWHrx8vq8P+vDnUh6W39+sETcEDAIGAYOAQSAfpM3wWVi8PMQHB8M/uVBrbggYBAwCBgGDgEGgzNfX4un7Wzjqy6g++OE5/g9PtRsCBgGDgEHAIGAQ+AbfzCHwAmk/4wAAAABJRU5ErkJggg==\" id=\"imageefecbbd21f\" transform=\"scale(1 -1)translate(0 -41)\" x=\"278.79019\" y=\"-129.551844\" width=\"68\" height=\"41\"/>\n","   </g>\n","   <g id=\"matplotlib.axis_15\">\n","    <g id=\"xtick_15\">\n","     <g id=\"line2d_29\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"282.186712\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_23\">\n","      <!-- 0 -->\n","      <g transform=\"translate(279.005462 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"xtick_16\">\n","     <g id=\"line2d_30\">\n","      <g>\n","       <use xlink:href=\"#m3141869086\" x=\"316.151929\" y=\"170.551844\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_24\">\n","      <!-- 5 -->\n","      <g transform=\"translate(312.970679 185.150281)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-35\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"text_25\">\n","     <!-- Key positions -->\n","     <g transform=\"translate(279.692126 198.828406)scale(0.1 -0.1)\">\n","      <use xlink:href=\"#DejaVuSans-4b\"/>\n","      <use xlink:href=\"#DejaVuSans-65\" x=\"60.576172\"/>\n","      <use xlink:href=\"#DejaVuSans-79\" x=\"122.099609\"/>\n","      <use xlink:href=\"#DejaVuSans-20\" x=\"181.279297\"/>\n","      <use xlink:href=\"#DejaVuSans-70\" x=\"213.066406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"276.542969\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"337.724609\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"389.824219\"/>\n","      <use xlink:href=\"#DejaVuSans-74\" x=\"417.607422\"/>\n","      <use xlink:href=\"#DejaVuSans-69\" x=\"456.816406\"/>\n","      <use xlink:href=\"#DejaVuSans-6f\" x=\"484.599609\"/>\n","      <use xlink:href=\"#DejaVuSans-6e\" x=\"545.78125\"/>\n","      <use xlink:href=\"#DejaVuSans-73\" x=\"609.160156\"/>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"matplotlib.axis_16\">\n","    <g id=\"ytick_15\">\n","     <g id=\"line2d_31\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"278.79019\" y=\"133.190104\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_16\">\n","     <g id=\"line2d_32\">\n","      <g>\n","       <use xlink:href=\"#m55a80ebdb0\" x=\"278.79019\" y=\"167.155322\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"patch_38\">\n","    <path d=\"M 278.79019 170.551844 \n","L 278.79019 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_39\">\n","    <path d=\"M 346.720625 170.551844 \n","L 346.720625 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_40\">\n","    <path d=\"M 278.79019 170.551844 \n","L 346.720625 170.551844 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"patch_41\">\n","    <path d=\"M 278.79019 129.793583 \n","L 346.720625 129.793583 \n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","   <g id=\"text_26\">\n","    <!-- Head 4 -->\n","    <g transform=\"translate(291.341033 123.793583)scale(0.12 -0.12)\">\n","     <use xlink:href=\"#DejaVuSans-48\"/>\n","     <use xlink:href=\"#DejaVuSans-65\" x=\"75.195312\"/>\n","     <use xlink:href=\"#DejaVuSans-61\" x=\"136.71875\"/>\n","     <use xlink:href=\"#DejaVuSans-64\" x=\"197.998047\"/>\n","     <use xlink:href=\"#DejaVuSans-20\" x=\"261.474609\"/>\n","     <use xlink:href=\"#DejaVuSans-34\" x=\"293.261719\"/>\n","    </g>\n","   </g>\n","  </g>\n","  <g id=\"axes_9\">\n","   <g id=\"patch_42\">\n","    <path d=\"M 366.250625 155.361622 \n","L 371.958425 155.361622 \n","L 371.958425 41.205622 \n","L 366.250625 41.205622 \n","z\n","\" style=\"fill: #ffffff\"/>\n","   </g>\n","   <g id=\"patch_43\">\n","    <path clip-path=\"url(#pad46710432)\" style=\"fill: #ffffff; stroke: #ffffff; stroke-width: 0.01; stroke-linejoin: miter\"/>\n","   </g>\n","   <image xlink:href=\"data:image/png;base64,\n","iVBORw0KGgoAAAANSUhEUgAAAAYAAAByCAYAAABwf6CfAAAAzUlEQVR4nLWVQQ7EMAgDqcT/v7qXPTUQ+gGmklHaY9Bgm6TJVf9fWfO51e7WzW0nFJhoJSYaxQQVBjl0u1gIKCSJoyscSaxTrdhV6jmAKN1VkLiegzVoiHorJA7mOLhRg1lhDvoNBjl0uyBeg/2QcyAha1SiuErUoivjnPhe5+xiISiHbjfhbk8k6PFKKrxoyK3kQsb3GkEam15OLPQba+aJRL9uvg3FgQi0S610cSQwYH8O3wjYDvPFhNoKiRv8etBIdI2FJ1FuhcQNxAMVLAxITCrWxAAAAABJRU5ErkJggg==\" id=\"imagea7e6970c64\" transform=\"scale(1 -1)translate(0 -114)\" x=\"366\" y=\"-41\" width=\"6\" height=\"114\"/>\n","   <g id=\"matplotlib.axis_17\">\n","    <g id=\"ytick_17\">\n","     <g id=\"line2d_33\">\n","      <defs>\n","       <path id=\"m9fbacd571a\" d=\"M 0 0 \n","L 3.5 0 \n","\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </defs>\n","      <g>\n","       <use xlink:href=\"#m9fbacd571a\" x=\"371.958425\" y=\"155.361622\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_27\">\n","      <!-- 0.0 -->\n","      <g transform=\"translate(378.958425 159.160841)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \n","L 1344 794 \n","L 1344 0 \n","L 684 0 \n","L 684 794 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-30\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_18\">\n","     <g id=\"line2d_34\">\n","      <g>\n","       <use xlink:href=\"#m9fbacd571a\" x=\"371.958425\" y=\"132.169869\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_28\">\n","      <!-- 0.2 -->\n","      <g transform=\"translate(378.958425 135.969088)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-32\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_19\">\n","     <g id=\"line2d_35\">\n","      <g>\n","       <use xlink:href=\"#m9fbacd571a\" x=\"371.958425\" y=\"108.978115\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_29\">\n","      <!-- 0.4 -->\n","      <g transform=\"translate(378.958425 112.777334)scale(0.1 -0.1)\">\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-34\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_20\">\n","     <g id=\"line2d_36\">\n","      <g>\n","       <use xlink:href=\"#m9fbacd571a\" x=\"371.958425\" y=\"85.786362\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_30\">\n","      <!-- 0.6 -->\n","      <g transform=\"translate(378.958425 89.585581)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n","Q 1688 2584 1439 2293 \n","Q 1191 2003 1191 1497 \n","Q 1191 994 1439 701 \n","Q 1688 409 2113 409 \n","Q 2538 409 2786 701 \n","Q 3034 994 3034 1497 \n","Q 3034 2003 2786 2293 \n","Q 2538 2584 2113 2584 \n","z\n","M 3366 4563 \n","L 3366 3988 \n","Q 3128 4100 2886 4159 \n","Q 2644 4219 2406 4219 \n","Q 1781 4219 1451 3797 \n","Q 1122 3375 1075 2522 \n","Q 1259 2794 1537 2939 \n","Q 1816 3084 2150 3084 \n","Q 2853 3084 3261 2657 \n","Q 3669 2231 3669 1497 \n","Q 3669 778 3244 343 \n","Q 2819 -91 2113 -91 \n","Q 1303 -91 875 529 \n","Q 447 1150 447 2328 \n","Q 447 3434 972 4092 \n","Q 1497 4750 2381 4750 \n","Q 2619 4750 2861 4703 \n","Q 3103 4656 3366 4563 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-36\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","    <g id=\"ytick_21\">\n","     <g id=\"line2d_37\">\n","      <g>\n","       <use xlink:href=\"#m9fbacd571a\" x=\"371.958425\" y=\"62.594609\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n","      </g>\n","     </g>\n","     <g id=\"text_31\">\n","      <!-- 0.8 -->\n","      <g transform=\"translate(378.958425 66.393827)scale(0.1 -0.1)\">\n","       <defs>\n","        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n","Q 1584 2216 1326 1975 \n","Q 1069 1734 1069 1313 \n","Q 1069 891 1326 650 \n","Q 1584 409 2034 409 \n","Q 2484 409 2743 651 \n","Q 3003 894 3003 1313 \n","Q 3003 1734 2745 1975 \n","Q 2488 2216 2034 2216 \n","z\n","M 1403 2484 \n","Q 997 2584 770 2862 \n","Q 544 3141 544 3541 \n","Q 544 4100 942 4425 \n","Q 1341 4750 2034 4750 \n","Q 2731 4750 3128 4425 \n","Q 3525 4100 3525 3541 \n","Q 3525 3141 3298 2862 \n","Q 3072 2584 2669 2484 \n","Q 3125 2378 3379 2068 \n","Q 3634 1759 3634 1313 \n","Q 3634 634 3220 271 \n","Q 2806 -91 2034 -91 \n","Q 1263 -91 848 271 \n","Q 434 634 434 1313 \n","Q 434 1759 690 2068 \n","Q 947 2378 1403 2484 \n","z\n","M 1172 3481 \n","Q 1172 3119 1398 2916 \n","Q 1625 2713 2034 2713 \n","Q 2441 2713 2670 2916 \n","Q 2900 3119 2900 3481 \n","Q 2900 3844 2670 4047 \n","Q 2441 4250 2034 4250 \n","Q 1625 4250 1398 4047 \n","Q 1172 3844 1172 3481 \n","z\n","\" transform=\"scale(0.015625)\"/>\n","       </defs>\n","       <use xlink:href=\"#DejaVuSans-30\"/>\n","       <use xlink:href=\"#DejaVuSans-2e\" x=\"63.623047\"/>\n","       <use xlink:href=\"#DejaVuSans-38\" x=\"95.410156\"/>\n","      </g>\n","     </g>\n","    </g>\n","   </g>\n","   <g id=\"LineCollection_1\"/>\n","   <g id=\"patch_44\">\n","    <path d=\"M 366.250625 155.361622 \n","L 369.104525 155.361622 \n","L 371.958425 155.361622 \n","L 371.958425 41.205622 \n","L 369.104525 41.205622 \n","L 366.250625 41.205622 \n","L 366.250625 155.361622 \n","z\n","\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n","   </g>\n","  </g>\n"," </g>\n"," <defs>\n","  <clipPath id=\"p018777eeb2\">\n","   <rect x=\"34.240625\" y=\"26.015401\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"p587607e1a4\">\n","   <rect x=\"115.757147\" y=\"26.015401\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"p444ff43be0\">\n","   <rect x=\"197.273668\" y=\"26.015401\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"p7632c1e4c6\">\n","   <rect x=\"278.79019\" y=\"26.015401\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"p0fb1186da0\">\n","   <rect x=\"34.240625\" y=\"129.793583\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"pf65d476a50\">\n","   <rect x=\"115.757147\" y=\"129.793583\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"p586cf36bc6\">\n","   <rect x=\"197.273668\" y=\"129.793583\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"pc03a8a644f\">\n","   <rect x=\"278.79019\" y=\"129.793583\" width=\"67.930435\" height=\"40.758261\"/>\n","  </clipPath>\n","  <clipPath id=\"pad46710432\">\n","   <rect x=\"366.250625\" y=\"41.205622\" width=\"5.7078\" height=\"114.156\"/>\n","  </clipPath>\n"," </defs>\n","</svg>\n"],"text/plain":["<Figure size 504x252 with 9 Axes>"]},"metadata":{"needs_background":"light"},"output_type":"display_data"}],"source":["d2l.show_heatmaps(\n","    dec_inter_attention_weights, xlabel='Key positions',\n","    ylabel='Query positions', titles=['Head %d' % i for i in range(1, 5)],\n","    figsize=(7, 3.5))"],"id":"c4229176"},{"cell_type":"markdown","metadata":{"origin_pos":72,"id":"46973525"},"source":["尽管transformer架构是为了“序列到序列”的学习而提出的，但正如我们将在本书后面提及的那样，transformer编码器或transformer解码器通常被单独用于不同的深度学习任务中。\n","\n","## 小结\n","\n","* transformer是编码器－解码器架构的一个实践，尽管在实际情况中编码器或解码器可以单独使用。\n","* 在transformer中，多头自注意力用于表示输入序列和输出序列，不过解码器必须通过掩蔽机制来保留自回归属性。\n","* transformer中的残差连接和层规范化是训练非常深度模型的重要工具。\n","* transformer模型中基于位置的前馈网络使用同一个多层感知机，作用是对所有序列位置的表示进行转换。\n","\n","## 练习\n","\n","1. 在实验中训练更深的transformer将如何影响训练速度和翻译效果？\n","1. 在transformer中使用加性注意力取代缩放点积注意力是不是个好办法？为什么？\n","1. 对于语言模型，我们应该使用transformer的编码器还是解码器，或者两者都用？如何设计？\n","1. 如果输入序列很长，transformer会面临什么挑战？为什么？\n","1. 如何提高transformer的计算速度和内存使用效率？提示：可以参考论文 :cite:`Tay.Dehghani.Bahri.ea.2020`。\n","1. 如果不使用卷积神经网络，如何设计基于transformer模型的图像分类任务？提示：可以参考Vision Transformer :cite:`Dosovitskiy.Beyer.Kolesnikov.ea.2021`。\n"],"id":"46973525"},{"cell_type":"markdown","metadata":{"origin_pos":74,"tab":["pytorch"],"id":"07b6980b"},"source":["[Discussions](https://discuss.d2l.ai/t/5756)\n"],"id":"07b6980b"}],"metadata":{"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"},"colab":{"provenance":[{"file_id":"https://github.com/d2l-ai/d2l-zh-pytorch-colab/blob/master/chapter_attention-mechanisms/attention-cues.ipynb","timestamp":1664003935597}],"toc_visible":true}},"nbformat":4,"nbformat_minor":5}